1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

[1.0.X] Fixed #8861 -- Added note on the availability of ModelForm.instance. Thanks to Ramiro Morales for the patch.

Merge of r11097 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@11102 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee
2009-06-24 14:23:24 +00:00
parent 34fbf191c1
commit b287f8a96f
2 changed files with 18 additions and 7 deletions

View File

@@ -370,11 +370,20 @@ 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
----------------