diff options
Diffstat (limited to 'docs/topics/forms/modelforms.txt')
| -rw-r--r-- | docs/topics/forms/modelforms.txt | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt index 690ca7f391..add581268b 100644 --- a/docs/topics/forms/modelforms.txt +++ b/docs/topics/forms/modelforms.txt @@ -397,16 +397,26 @@ to be rendered first, we could specify the following ``ModelForm``:: ... model = Book ... fields = ['title', 'author'] +.. _overriding-modelform-clean-method: Overriding the clean() method ----------------------------- You can override the ``clean()`` method on a model form to provide additional -validation in the same way you can on a normal form. However, by default the -``clean()`` method validates the uniqueness of fields that are marked as -``unique``, ``unique_together`` or ``unique_for_date|month|year`` on the model. -Therefore, if you would like to override the ``clean()`` method and maintain the -default validation, you must call the parent class's ``clean()`` method. +validation in the same way you can on a normal form. + +In this regard, model forms have two specific characteristics when compared to +forms: + +By default the ``clean()`` method validates the uniqueness of fields that are +marked as ``unique``, ``unique_together`` or ``unique_for_date|month|year`` on +the model. Therefore, if you would like to override the ``clean()`` method and +maintain the default validation, you must call the parent class's ``clean()`` +method. + +Also, a model form instance bound to a model object will contain a +``self.instance`` attribute that gives model form methods access to that +specific model instance. Form inheritance ---------------- @@ -611,7 +621,7 @@ Just like with ``ModelForms``, by default the ``clean()`` method of a the unique constraints on your model (either ``unique``, ``unique_together`` or ``unique_for_date|month|year``). If you want to overide the ``clean()`` method on a ``model_formset`` and maintain this validation, you must call the parent -classes ``clean`` method:: +class's ``clean`` method:: class MyModelFormSet(BaseModelFormSet): def clean(self): |
