Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11128 -- Misc. fixes and improvements to the model forms doc. …

…Thanks Ramiro and Alex.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10795 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7ba62f2c15b4658d3280bcb588670a8b6d2b65fd 1 parent 975ec18
Karen Tracey authored May 17, 2009

Showing 1 changed file with 22 additions and 28 deletions. Show diff stats Hide diff stats

  1. 50  docs/topics/forms/modelforms.txt
50  docs/topics/forms/modelforms.txt
@@ -400,10 +400,10 @@ Overriding the clean() method
400 400
 
401 401
 You can override the ``clean()`` method on a model form to provide additional
402 402
 validation in the same way you can on a normal form. However, by default the
403  
-``clean()`` method validates the uniqueness of fields that are marked as unique
404  
-or unique_together on the model. Therefore, if you would like to override
405  
-the ``clean()`` method and maintain the default validation, you must call the
406  
-parent class's ``clean()`` method.
  403
+``clean()`` method validates the uniqueness of fields that are marked as
  404
+``unique``, ``unique_together`` or ``unique_for_date|month|year`` on the model.
  405
+Therefore, if you would like to override the ``clean()`` method and maintain the
  406
+default validation, you must call the parent class's ``clean()`` method.
407 407
 
408 408
 Form inheritance
409 409
 ----------------
@@ -515,22 +515,6 @@ exclude::
515 515
 
516 516
 .. _saving-objects-in-the-formset:
517 517
 
518  
-Overriding clean() method
519  
--------------------------
520  
-
521  
-You can override the ``clean()`` method to provide custom validation to
522  
-the whole formset at once. By default, the ``clean()`` method will validate
523  
-that none of the data in the formsets violate the unique constraints on your
524  
-model (both field ``unique`` and model ``unique_together``). To maintain this
525  
-default behavior be sure you call the parent's ``clean()`` method::
526  
-
527  
-    class MyModelFormSet(BaseModelFormSet):
528  
-        def clean(self):
529  
-            super(MyModelFormSet, self).clean()
530  
-            # example custom validation across forms in the formset:
531  
-            for form in self.forms:
532  
-                # your custom formset validation
533  
-
534 518
 Saving objects in the formset
535 519
 -----------------------------
536 520
 
@@ -615,19 +599,25 @@ than that of a "normal" formset. The only difference is that we call
615 599
 ``formset.save()`` to save the data into the database. (This was described
616 600
 above, in :ref:`saving-objects-in-the-formset`.)
617 601
 
618  
-
619 602
 Overiding ``clean()`` on a ``model_formset``
620 603
 --------------------------------------------
621 604
 
622 605
 Just like with ``ModelForms``, by default the ``clean()`` method of a
623  
-``model_formset`` will validate that none of the items in the formset validate
624  
-the unique constraints on your model(either unique or unique_together).  If you
625  
-want to overide the ``clean()`` method on a ``model_formset`` and maintain this
626  
-validation, you must call the parent classes ``clean`` method.
  606
+``model_formset`` will validate that none of the items in the formset violate
  607
+the unique constraints on your model (either ``unique``, ``unique_together`` or
  608
+``unique_for_date|month|year``).  If you want to overide the ``clean()`` method
  609
+on a ``model_formset`` and maintain this validation, you must call the parent
  610
+classes ``clean`` method::
627 611
 
  612
+    class MyModelFormSet(BaseModelFormSet):
  613
+        def clean(self):
  614
+            super(MyModelFormSet, self).clean()
  615
+            # example custom validation across forms in the formset:
  616
+            for form in self.forms:
  617
+                # your custom formset validation
628 618
 
629 619
 Using a custom queryset
630  
-~~~~~~~~~~~~~~~~~~~~~~~
  620
+-----------------------
631 621
 
632 622
 As stated earlier, you can override the default queryset used by the model
633 623
 formset::
@@ -650,7 +640,9 @@ Note that we pass the ``queryset`` argument in both the ``POST`` and ``GET``
650 640
 cases in this example.
651 641
 
652 642
 Using the formset in the template
653  
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  643
+---------------------------------
  644
+
  645
+.. highlight:: html+django
654 646
 
655 647
 There are three ways to render a formset in a Django template.
656 648
 
@@ -705,6 +697,8 @@ the model formset, in the ``POST`` case, will work correctly. (This example
705 697
 assumes a primary key named ``id``. If you've explicitly defined your own
706 698
 primary key that isn't called ``id``, make sure it gets rendered.)
707 699
 
  700
+.. highlight:: python
  701
+
708 702
 Inline formsets
709 703
 ===============
710 704
 
@@ -745,7 +739,7 @@ the following model::
745 739
 
746 740
 To resolve this, you can use ``fk_name`` to ``inlineformset_factory``::
747 741
 
748  
-    >>> FrienshipFormSet = inlineformset_factory(Friend, Friendship, fk_name="from_friend")
  742
+    >>> FriendshipFormSet = inlineformset_factory(Friend, Friendship, fk_name="from_friend")
749 743
 
750 744
 Using an inline formset in a view
751 745
 ---------------------------------

0 notes on commit 7ba62f2

Please sign in to comment.
Something went wrong with that request. Please try again.