Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.5.x] Fixed #21539 -- Added example of modelformset_factory's form …

…argument

Backport of 1fa681e from master
  • Loading branch information...
commit e4174da34ab239f04d9c79fec9822b01d63e453b 1 parent a53820b
Alasdair Nicol authored December 01, 2013 timgraham committed December 14, 2013

Showing 1 changed file with 24 additions and 0 deletions. Show diff stats Hide diff stats

  1. 24  docs/topics/forms/modelforms.txt
24  docs/topics/forms/modelforms.txt
@@ -646,6 +646,30 @@ instances of the model, you can specify an empty QuerySet::
646 646
 
647 647
    >>> AuthorFormSet(queryset=Author.objects.none())
648 648
 
  649
+Changing the ``form``
  650
+---------------------
  651
+
  652
+By default, when you use ``modelformset_factory``, a model form will
  653
+be created using :func:`~django.forms.models.modelform_factory`.
  654
+Often, it can be useful to specify a custom model form. For example,
  655
+you can create a custom model form that has custom validation::
  656
+
  657
+    class AuthorForm(forms.ModelForm):
  658
+        class Meta:
  659
+            model = Author
  660
+            fields = ('name', 'title')
  661
+
  662
+        def clean_name(self):
  663
+            # custom validation for the name field
  664
+            ...
  665
+
  666
+Then, pass your model form to the factory function::
  667
+
  668
+    AuthorFormSet = modelformset_factory(Author, form=AuthorForm)
  669
+
  670
+It is not always necessary to define a custom model form. The
  671
+``modelformset_factory`` function has several arguments which are
  672
+passed through to ``modelform_factory``, which are described below.
649 673
 
650 674
 Controlling which fields are used with ``fields`` and ``exclude``
651 675
 -----------------------------------------------------------------

0 notes on commit e4174da

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