djangodocs.org

1293 sections across all versions Narrow to Django 6.0 (current) →

Reference

Form validation happens when the data is cleaned. If you want to customize this process, there are various places to make changes, each one serving a different purpose. Three types of cleaning methods are run during form processing.

dev

Reference

Form validation happens when the data is cleaned. If you want to customize this process, there are various places to make changes, each one serving a different purpose. Three types of cleaning methods are run during form processing.

4.2 5.0 5.1 5.2 6.0

Topic guide Creating forms from models

There are two main steps involved in validating a ModelForm: Validating the form Validating the model instance Just like normal form validation, model form validation is triggered implicitly when calling is_valid() or accessing the errors attribute and explicitly when calling …

dev

Topic guide Creating forms from models ModelForm

There are two main steps involved in validating a ModelForm: Validating the form Validating the model instance Just like normal form validation, model form validation is triggered implicitly when calling is_valid() or accessing the errors attribute and explicitly when calling …

4.2 5.0 5.1 5.2 6.0

Reference The Django admin site

The admin uses ModelForm. To add custom validation, provide your own ModelForm: Then configure the ModelAdmin to use the form: Or configure an InlineModelAdmin to use the form: It is important that you use a ModelForm; otherwise things can break.

dev

How validators are run

Reference Validators

See the form validation for more information on how validators are run in forms, and Validating objects for how they’re run in models.

dev

Reference Form fields

Upon form validation, these fields will place either one model object (in the case of ModelChoiceField) or multiple model objects (in the case of ModelMultipleChoiceField) into the cleaned_data dictionary of the form.

dev

Reference Form fields

Upon form validation, these fields will place either one model object (in the case of ModelChoiceField) or multiple model objects (in the case of ModelMultipleChoiceField) into the cleaned_data dictionary of the form.

4.2 5.0 5.1 5.2 6.0

blank

Reference Model field reference Field options

Note that this is different than null. null is purely database-related, whereas blank is validation-related. If a field has blank=True, form validation will allow entry of an empty value. If a field has blank=False, the field will be required.

Testing in Django

Topic guide

Testing a web application is a complex task, because a web application is made of several layers of logic – from HTTP-level request handling, to form validation and processing, to template rendering.

dev

Testing in Django

Topic guide

Testing a web application is a complex task, because a web application is made of several layers of logic – from HTTP-level request handling, to form validation and processing, to template rendering.

4.2 5.0 5.1 5.2 6.0

Field options

Topic guide Models

Default is False. choices : A sequence of 2-value tuples, a mapping, an enumeration type, or a callable (that expects no arguments and returns any of the previous formats), to use as choices for this field.

dev

Field options

Topic guide Models Fields

Default is False. choices : A sequence of 2-value tuples, a mapping, an enumeration type, or a callable (that expects no arguments and returns any of the previous formats), to use as choices for this field.

4.2 5.0 5.1 5.2 6.0

Release notes Django 1.2 release notes

Much of the validation work for ModelForms has been moved down to the model level. As a result, the first time you call ModelForm.is_valid(), access ModelForm.errors or otherwise trigger form validation, your model will be cleaned in-place.

dev