summaryrefslogtreecommitdiff
path: root/docs/topics/forms
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-05-07 12:17:52 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-05-07 12:17:52 +0000
commitf259494f827b24228bbbadb1d118a09f8e6329ac (patch)
treeadecf8c59d436db454279a378b44bb28d4cccd3f /docs/topics/forms
parenteb81d5acb3e1fee57153c0a4719e3f26ae66c5cd (diff)
Fixed #9493 -- Corrected error handling of formsets that violate unique constraints across the component forms. Thanks to Alex Gaynor for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10682 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/topics/forms')
-rw-r--r--docs/topics/forms/modelforms.txt83
1 files changed, 55 insertions, 28 deletions
diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt
index be67a38b6f..8ccf9b0cfc 100644
--- a/docs/topics/forms/modelforms.txt
+++ b/docs/topics/forms/modelforms.txt
@@ -45,61 +45,61 @@ the full list of conversions:
Model field Form field
=============================== ========================================
``AutoField`` Not represented in the form
-
+
``BooleanField`` ``BooleanField``
-
+
``CharField`` ``CharField`` with ``max_length`` set to
the model field's ``max_length``
-
+
``CommaSeparatedIntegerField`` ``CharField``
-
+
``DateField`` ``DateField``
-
+
``DateTimeField`` ``DateTimeField``
-
+
``DecimalField`` ``DecimalField``
-
+
``EmailField`` ``EmailField``
-
+
``FileField`` ``FileField``
-
+
``FilePathField`` ``CharField``
-
+
``FloatField`` ``FloatField``
-
+
``ForeignKey`` ``ModelChoiceField`` (see below)
-
+
``ImageField`` ``ImageField``
-
+
``IntegerField`` ``IntegerField``
-
+
``IPAddressField`` ``IPAddressField``
-
+
``ManyToManyField`` ``ModelMultipleChoiceField`` (see
below)
-
+
``NullBooleanField`` ``CharField``
-
+
``PhoneNumberField`` ``USPhoneNumberField``
(from ``django.contrib.localflavor.us``)
-
+
``PositiveIntegerField`` ``IntegerField``
-
+
``PositiveSmallIntegerField`` ``IntegerField``
-
+
``SlugField`` ``SlugField``
-
+
``SmallIntegerField`` ``IntegerField``
-
- ``TextField`` ``CharField`` with
+
+ ``TextField`` ``CharField`` with
``widget=forms.Textarea``
-
+
``TimeField`` ``TimeField``
-
+
``URLField`` ``URLField`` with ``verify_exists`` set
to the model field's ``verify_exists``
-
- ``XMLField`` ``CharField`` with
+
+ ``XMLField`` ``CharField`` with
``widget=forms.Textarea``
=============================== ========================================
@@ -487,7 +487,7 @@ queryset that includes all objects in the model (e.g.,
Alternatively, you can create a subclass that sets ``self.queryset`` in
``__init__``::
-
+
from django.forms.models import BaseModelFormSet
class BaseAuthorFormSet(BaseModelFormSet):
@@ -515,6 +515,22 @@ exclude::
.. _saving-objects-in-the-formset:
+Overriding clean() method
+-------------------------
+
+You can override the ``clean()`` method to provide custom validation to
+the whole formset at once. By default, the ``clean()`` method will validate
+that none of the data in the formsets violate the unique constraints on your
+model (both field ``unique`` and model ``unique_together``). To maintain this
+default behavior be sure you call the parent's ``clean()`` method::
+
+ class MyModelFormSet(BaseModelFormSet):
+ def clean(self):
+ super(MyModelFormSet, self).clean()
+ # example custom validation across forms in the formset:
+ for form in self.forms:
+ # your custom formset validation
+
Saving objects in the formset
-----------------------------
@@ -599,6 +615,17 @@ than that of a "normal" formset. The only difference is that we call
``formset.save()`` to save the data into the database. (This was described
above, in :ref:`saving-objects-in-the-formset`.)
+
+Overiding ``clean()`` on a ``model_formset``
+--------------------------------------------
+
+Just like with ``ModelForms``, by default the ``clean()`` method of a
+``model_formset`` will validate that none of the items in the formset validate
+the unique constraints on your model(either unique or unique_together). If you
+want to overide the ``clean()`` method on a ``model_formset`` and maintain this
+validation, you must call the parent classes ``clean`` method.
+
+
Using a custom queryset
~~~~~~~~~~~~~~~~~~~~~~~