diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt
a
|
b
|
|
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 | 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 |
| 606 | ``model_formset`` will validate that none of the items in the formset violate |
| 607 | the unique constraints on your model (either unique or unique_together). If you |
625 | 608 | want to overide the ``clean()`` method on a ``model_formset`` and maintain this |
626 | | validation, you must call the parent classes ``clean`` method. |
| 609 | validation, you must call the parent classes ``clean`` method:: |
627 | 610 | |
| 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 |
628 | 617 | |
629 | 618 | Using a custom queryset |
630 | | ~~~~~~~~~~~~~~~~~~~~~~~ |
| 619 | ----------------------- |
631 | 620 | |
632 | 621 | As stated earlier, you can override the default queryset used by the model |
633 | 622 | formset:: |
… |
… |
|
650 | 639 | cases in this example. |
651 | 640 | |
652 | 641 | Using the formset in the template |
653 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 642 | --------------------------------- |
| 643 | |
| 644 | .. highlight:: html+django |
654 | 645 | |
655 | 646 | There are three ways to render a formset in a Django template. |
656 | 647 | |
… |
… |
|
705 | 696 | assumes a primary key named ``id``. If you've explicitly defined your own |
706 | 697 | primary key that isn't called ``id``, make sure it gets rendered.) |
707 | 698 | |
| 699 | .. highlight:: python |
| 700 | |
708 | 701 | Inline formsets |
709 | 702 | =============== |
710 | 703 | |
… |
… |
|
745 | 738 | |
746 | 739 | To resolve this, you can use ``fk_name`` to ``inlineformset_factory``:: |
747 | 740 | |
748 | | >>> FrienshipFormSet = inlineformset_factory(Friend, Friendship, fk_name="from_friend") |
| 741 | >>> FriendshipFormSet = inlineformset_factory(Friend, Friendship, fk_name="from_friend") |
749 | 742 | |
750 | 743 | Using an inline formset in a view |
751 | 744 | --------------------------------- |