In a form
in django
, what is the difference between a validator
for a field and a clean_<field>
method for that field?
Django will first run the built-in (default) field validators, then your custom field validators (using validators=[your_validator]
in your models).
Then, Django will then execute the clean()
and clean<field>()
methods.
The main difference between a validator
and a clean_<field>()
method is that the latter is only meant for forms. A validator
can be used for both your forms and your models (and hence will also be used in e.g. the admin interface).
Also, overriding the clean_<field>()
method is the recommended way to validate data against items in your database.
More info on https://docs.djangoproject.com/en/1.6/ref/forms/validation/.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With