I have a form that allows users to upload text AND a file. However, I'd like to make it valid even if the user doesn't upload the file (file is optional). However, in Django, it is not allowing me to get past "clean(self)". I just want it simple--if text box, pass. If no text , return error.
class PieceForm(forms.Form):
text = forms.CharField(max_length=600)
file = forms.FileField()
def clean(self):
cleaned_data = self.cleaned_data
text = cleaned_data.get('text')
file = cleaned_data.get('file')
return cleaned_data
In my views...
form = PieceForm(request.POST, request.FILES)
if form.is_valid():
print 'It's valid!' ........this only prints if there is a file!