diff options
| author | Tim Graham <timograham@gmail.com> | 2013-07-08 08:29:28 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-07-08 08:29:28 -0400 |
| commit | 181f63c22dc0de823031be84b86277b282e4e221 (patch) | |
| tree | 39fb8f2392f108b17d7008a9006a03ad972eda3e /docs/topics | |
| parent | 9383e37a7636879a0f889c0bca38675f7fc85f5b (diff) | |
Fixed #12346 -- Added a note on how to validate InlineFormSets.
Thanks johnsmith for the suggestion.
Diffstat (limited to 'docs/topics')
| -rw-r--r-- | docs/topics/forms/modelforms.txt | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt index d961ee41d5..381a97f25a 100644 --- a/docs/topics/forms/modelforms.txt +++ b/docs/topics/forms/modelforms.txt @@ -857,14 +857,16 @@ 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`` +.. _model-formsets-overriding-clean: + +Overriding ``clean()`` on a ``ModelFormSet`` -------------------------------------------- Just like with ``ModelForms``, by default the ``clean()`` method of a -``model_formset`` will validate that none of the items in the formset violate +``ModelFormSet`` will validate that none of the items in the formset violate the unique constraints on your model (either ``unique``, ``unique_together`` or ``unique_for_date|month|year``). If you want to override the ``clean()`` method -on a ``model_formset`` and maintain this validation, you must call the parent +on a ``ModelFormSet`` and maintain this validation, you must call the parent class's ``clean`` method:: from django.forms.models import BaseModelFormSet @@ -969,6 +971,8 @@ primary key that isn't called ``id``, make sure it gets rendered.) Inline formsets =============== +.. class:: models.BaseInlineFormSet + Inline formsets is a small abstraction layer on top of model formsets. These simplify the case of working with related objects via a foreign key. Suppose you have these two models:: @@ -1000,6 +1004,13 @@ a particular author, you could do this:: :ref:`Manually rendered can_delete and can_order <manually-rendered-can-delete-and-can-order>`. +Overriding ``clean()`` on an ``InlineFormSet`` +---------------------------------------------- + +See :ref:`model-formsets-overriding-clean`, but subclass +:class:`~models.BaseInlineFormSet` rather than +:class:`~models.BaseModelFormSet`. + More than one foreign key to the same model ------------------------------------------- |
