views.py
from django.views.generic.edit import FormView
from .forms import UploadForm
from .models import Attachment
class UploadView(FormView):
template_name = 'form.html'
form_class = UploadForm
success_url = '/done/'
def form_valid(self, form):
for each in form.cleaned_data['attachments']:
Attachment.objects.create(file=each)
return super(UploadView, self).form_valid(form)
models.py
from django.db import models
class Attachment(models.Model):
file = models.FileField(upload_to='')
forms.py
from django import forms
from multiupload.fields import MultiFileField
class UploadForm(forms.Form):
attachments = MultiFileField(min_num=1)
upload.html
{% extends 'mainpage/homepage.html' %}
{% load static %}
{% block content %}
<form enctype="multipart/form-data" method="post">
{% csrf_token %}
<input type="file" name="myfiles" multiple>
<button type="submit">Upload</button>
</form>
{% if uploaded_file_url %}
<p>File uploaded at: <a href="{{ uploaded_file_url }}">{{ uploaded_file_url }}</a></p>
{% endif %}
<p><a href="">Return to home</a></p>
{% endblock %}
Как передать список загруженных файлов в views.py все доки просто пример кидают а подключить как не понимаю.