O'Reilly logo

Django Unleashed by Andrew Pinkham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

7.3.8 Understanding ModelForm Validation

One of Django’s central gotchas revolves around misunderstanding validation in forms inheriting ModelForm.

Much like a regular Django form, a ModelForm runs all of the clean and validator methods associated with the form (which is why we keep clean_name() and clean_slug()). However, a ModelForm also uses model validation.

That’s right: models also provide validation! Models supply a full_clean() method, which is similar to the form’s is_valid() method. Model validation is very similar to form validation. The model starts by validating individual fields with validators and clean methods. The model itself may supply field-specific clean methods, just as the form does, and the model may also similarly supply ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required