summaryrefslogtreecommitdiff
path: root/docs/topics/forms/modelforms.txt
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-06-10 12:46:04 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-06-10 12:46:04 +0000
commit6ad26e6acc34134752d8728bf6dc6e592883bbfa (patch)
tree25d0bd62da33fa253817db0fb2b6295a783c027b /docs/topics/forms/modelforms.txt
parent6c36d4c4f8379433cdce150a64dad6a1f16097cd (diff)
Fixed #10845 -- Clarified the examples for using ModelForms with fields or exclude specified. Thanks to Andrew Durdin for the suggestion.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10972 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/topics/forms/modelforms.txt')
-rw-r--r--docs/topics/forms/modelforms.txt23
1 files changed, 13 insertions, 10 deletions
diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt
index 370ac887b7..690ca7f391 100644
--- a/docs/topics/forms/modelforms.txt
+++ b/docs/topics/forms/modelforms.txt
@@ -323,16 +323,19 @@ Since the Author model has only 3 fields, 'name', 'title', and
to be empty, and does not provide a default value for the missing fields,
any attempt to ``save()`` a ``ModelForm`` with missing fields will fail.
To avoid this failure, you must instantiate your model with initial values
- for the missing, but required fields, or use ``save(commit=False)`` and
- manually set any extra required fields::
+ for the missing, but required fields::
- instance = Instance(required_field='value')
- form = InstanceForm(request.POST, instance=instance)
- new_instance = form.save()
+ author = Author(title='Mr')
+ form = PartialAuthorForm(request.POST, instance=author)
+ form.save()
- instance = form.save(commit=False)
- instance.required_field = 'new value'
- new_instance = instance.save()
+ Alternatively, you can use ``save(commit=False)`` and manually set
+ any extra required fields::
+
+ form = PartialAuthorForm(request.POST)
+ author = form.save(commit=False)
+ author.title = 'Mr'
+ author.save()
See the `section on saving forms`_ for more details on using
``save(commit=False)``.
@@ -563,8 +566,8 @@ number of objects needed::
>>> formset.initial
[{'id': 1, 'name': u'Charles Baudelaire'}, {'id': 3, 'name': u'Paul Verlaine'}]
-If the value of ``max_num`` is higher than the number of objects returned, up to
-``extra`` additional blank forms will be added to the formset, so long as the
+If the value of ``max_num`` is higher than the number of objects returned, up to
+``extra`` additional blank forms will be added to the formset, so long as the
total number of forms does not exceed ``max_num``::
>>> AuthorFormSet = modelformset_factory(Author, max_num=4, extra=2)