1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #8209: ModelForms now validate unique constraints. Alex Gaynor did much of this work, and Brian Rosner helped as well.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8805 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss
2008-09-01 19:08:08 +00:00
parent 5f31e9bd33
commit ea05e61b2b
5 changed files with 229 additions and 11 deletions

View File

@@ -338,6 +338,16 @@ parameter when declaring the form field::
... class Meta:
... model = Article
Overriding the clean() method
-----------------------------
You can overide 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
on the model, and those marked as unque_together, if you would like to overide
the ``clean()`` method and maintain the default validation you must call the
parent class's ``clean()`` method.
Form inheritance
----------------
@@ -500,4 +510,4 @@ books of a specific author. Here is how you could accomplish this::
>>> from django.forms.models import inlineformset_factory
>>> BookFormSet = inlineformset_factory(Author, Book)
>>> author = Author.objects.get(name=u'Orson Scott Card')
>>> formset = BookFormSet(instance=author)
>>> formset = BookFormSet(instance=author)