Ticket #11128: 11128-model_fset_doc_fixes-r10793.diff

File 11128-model_fset_doc_fixes-r10793.diff, 3.0 KB (added by Ramiro Morales, 15 years ago)
  • docs/topics/forms/modelforms.txt

    diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt
    a b  
    515515
    516516.. _saving-objects-in-the-formset:
    517517
    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 
    534518Saving objects in the formset
    535519-----------------------------
    536520
     
    615599``formset.save()`` to save the data into the database. (This was described
    616600above, in :ref:`saving-objects-in-the-formset`.)
    617601
    618 
    619602Overiding ``clean()`` on a ``model_formset``
    620603--------------------------------------------
    621604
    622605Just 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
     606``model_formset`` will validate that none of the items in the formset violate
     607the unique constraints on your model (either unique or unique_together).  If you
    625608want to overide the ``clean()`` method on a ``model_formset`` and maintain this
    626 validation, you must call the parent classes ``clean`` method.
     609validation, you must call the parent classes ``clean`` method::
    627610
     611    class MyModelFormSet(BaseModelFormSet):
     612        def clean(self):
     613            super(MyModelFormSet, self).clean()
     614            # example custom validation across forms in the formset:
     615            for form in self.forms:
     616                # your custom formset validation
    628617
    629618Using a custom queryset
    630 ~~~~~~~~~~~~~~~~~~~~~~~
     619-----------------------
    631620
    632621As stated earlier, you can override the default queryset used by the model
    633622formset::
     
    650639cases in this example.
    651640
    652641Using the formset in the template
    653 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     642---------------------------------
     643
     644.. highlight:: html+django
    654645
    655646There are three ways to render a formset in a Django template.
    656647
     
    705696assumes a primary key named ``id``. If you've explicitly defined your own
    706697primary key that isn't called ``id``, make sure it gets rendered.)
    707698
     699.. highlight:: python
     700
    708701Inline formsets
    709702===============
    710703
     
    745738
    746739To resolve this, you can use ``fk_name`` to ``inlineformset_factory``::
    747740
    748     >>> FrienshipFormSet = inlineformset_factory(Friend, Friendship, fk_name="from_friend")
     741    >>> FriendshipFormSet = inlineformset_factory(Friend, Friendship, fk_name="from_friend")
    749742
    750743Using an inline formset in a view
    751744---------------------------------
Back to Top