summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorAlasdair Nicol <alasdair@thenicols.net>2013-12-01 02:05:15 +0000
committerTim Graham <timograham@gmail.com>2013-12-14 16:35:14 -0500
commit1fa681ee11ac234cdc515338397625f514e85b73 (patch)
tree4ec41f5256c19f28a78563f6a347857d215de85f /docs
parent164a3a388cfeeaec9ae240e7a8c8abcdc104a4d4 (diff)
Fixed #21539 -- Added example of modelformset_factory's form argument
Diffstat (limited to 'docs')
-rw-r--r--docs/topics/forms/modelforms.txt24
1 files changed, 24 insertions, 0 deletions
diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt
index 394cf1f319..e98fcb0344 100644
--- a/docs/topics/forms/modelforms.txt
+++ b/docs/topics/forms/modelforms.txt
@@ -760,6 +760,30 @@ instances of the model, you can specify an empty QuerySet::
>>> AuthorFormSet(queryset=Author.objects.none())
+Changing the ``form``
+---------------------
+
+By default, when you use ``modelformset_factory``, a model form will
+be created using :func:`~django.forms.models.modelform_factory`.
+Often, it can be useful to specify a custom model form. For example,
+you can create a custom model form that has custom validation::
+
+ class AuthorForm(forms.ModelForm):
+ class Meta:
+ model = Author
+ fields = ('name', 'title')
+
+ def clean_name(self):
+ # custom validation for the name field
+ ...
+
+Then, pass your model form to the factory function::
+
+ AuthorFormSet = modelformset_factory(Author, form=AuthorForm)
+
+It is not always necessary to define a custom model form. The
+``modelformset_factory`` function has several arguments which are
+passed through to ``modelform_factory``, which are described below.
.. _controlling-fields-with-fields-and-exclude: