I am not happy with this snippet from the django docs:
from django.views.generic.edit import FormView
from .forms import FileFieldForm
class FileFieldView(FormView):
form_class = FileFieldForm
template_name = 'upload.html' # Replace with your template.
success_url = '...' # Replace with your URL or reverse().
def post(self, request, *args, **kwargs):
form_class = self.get_form_class()
form = self.get_form(form_class)
files = request.FILES.getlist('file_field')
if form.is_valid():
for f in files:
... # Do something with each file.
return self.form_valid(form)
else:
return self.form_invalid(form)
Source: https://docs.djangoproject.com/en/1.11/topics/http/file-uploads/#uploading-multiple-files
My problem: The form instance can't validate the files.
AFAIK in the method form.clean() I don't have a list of files.
I can work around this, but it breaks the nice separation of concerns which
I usually get with the nice django form library :-)
Imagine my app receives three files. Is there a way to validate these files inside form.clean()?
Regards,
Thomas Güttler