In Django 1.4 documentation, it says that clean_<fieldname> methods are run first, then form clean method is executed.
I have the following code sample. The form is used with FormPreview. When pmid field is empty in the form, it should throw ValidationError exception, but it doesn’t happen.
class MyForm(forms.Form):
pmid = forms.CharField()
.. other fields ..
def clean(self):
cd = super(MyForm, self).clean()
cd['pmid'] # returns KeyError and it's not in cd
return cd
I don’t override any clean_<field> method.
First, if all you want to do is ensure a field is not blank, then just add
required=Trueto it. For example:And you’re done.
However, even if you couldn’t do it that way, you still wouldn’t validate it in
clean, but inclean_<fieldname>as the docs describe.