I have a situation that is confusing me. I have a form to upload a file. From my understanding, when 'clean' is called on the form, the 'file1' field should have already been cleaned and available in cleaned_data. However, under some circumstances it is, sometimes not. But when calling is_valid I can get
None None None Total size 0 Which means the file1 was not cleaned. Here is my code.. Shouldn't the file1 be available in cleaned_data to check its size at this point always? If not, how can I access the request.FILES from inside the form rather than the view? --- (in view) document_form = DocumentFileUploadForm(request.POST, request.FILES) if document_form.is_valid(): ... (in forms) def check_file_size_limit(form): # calculate and check total size of files on form is not exceeded size = 0; for i in range(1, 4): f = form.cleaned_data.get("file%d" % (i,)) print f if f is not None: size += f.size # UploadedFile object is much easier now print "Total size %d" % (size,) if size > settings.MAX_FILE_SIZE: raise ValidationError("Total file size exceeds the allowed limit") return size class DocumentFileUploadForm(forms.Form): file1 = forms.FileField(label="Upload CV / Folio", required=False) def clean(self): size = check_file_size_limit(self) if size == 0: raise ValidationError("Please attach a CV!") return self.cleaned_data --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---