From eac54911f5df8a31377fecd37b2bf34f0afef169 Mon Sep 17 00:00:00 2001 From: Chris Cahoon Date: Thu, 25 Jun 2009 15:42:51 +0000 Subject: [soc2009/http-wsgi-improvements] Merged up to 11103 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/http-wsgi-improvements@11109 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/topics/forms/modelforms.txt | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'docs/topics/forms/modelforms.txt') 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): -- cgit v1.3