diff options
| author | Tim Graham <timograham@gmail.com> | 2012-11-05 07:14:40 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2012-11-05 18:24:28 -0500 |
| commit | d3fd8a151231726adacb99bdbcd573f95ce32262 (patch) | |
| tree | 315c4d7e492c42ba5ad38581073d1c39bb5be750 /docs/ref | |
| parent | 78f66691ee7974e0ca546f09573394395a68b443 (diff) | |
Fixed #15591 - Clarified interaction between ModelForm and model validation.
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/models/instances.txt | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt index b4872e3e5c..1d0ac08061 100644 --- a/docs/ref/models/instances.txt +++ b/docs/ref/models/instances.txt @@ -67,9 +67,9 @@ Validating objects There are three steps involved in validating a model: -1. Validate the model fields -2. Validate the model as a whole -3. Validate the field uniqueness +1. Validate the model fields - :meth:`Model.clean_fields()` +2. Validate the model as a whole - :meth:`Model.clean()` +3. Validate the field uniqueness - :meth:`Model.validate_unique()` All three steps are performed when you call a model's :meth:`~Model.full_clean()` method. @@ -97,17 +97,20 @@ not be corrected by the user. Note that ``full_clean()`` will *not* be called automatically when you call your model's :meth:`~Model.save()` method, nor as a result of -:class:`~django.forms.ModelForm` validation. You'll need to call it manually -when you want to run one-step model validation for your own manually created -models. +:class:`~django.forms.ModelForm` validation. In the case of +:class:`~django.forms.ModelForm` validation, :meth:`Model.clean_fields()`, +:meth:`Model.clean()`, and :meth:`Model.validate_unique()` are all called +individually. -Example:: +You'll need to call ``full_clean`` manually when you want to run one-step model +validation for your own manually created models. For example:: try: article.full_clean() except ValidationError as e: # Do something based on the errors contained in e.message_dict. # Display them to a user, or handle them programatically. + pass The first step ``full_clean()`` performs is to clean each individual field. |
