I’m using Django’s ModelForms and would like to have validation on both models and forms. I’m rendering form using:
{{ form.as_table }}
What is the proper place to put validation on per-field basis (like forms’ clean_fieldname) and as a whole (like forms’ clean)?
I’d like to minimize amount of code written and not write the same validators twice (in both models and forms). Also, I’d like per-field validation errors to be shown over proper form field, not have all errors placed on top of the form (so not all checks in models’ clean).
You might want to use the custom validators introduced in Django 1.2.
Don’t forget that unless you are using a
ModelFormyou have to explicitly performs the model validation with a call to the full_clean() method on your model instance.