Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #10845 -- Clarified the examples for using ModelForms with fiel…

…ds 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
  • Loading branch information...
commit 6ad26e6acc34134752d8728bf6dc6e592883bbfa 1 parent 6c36d4c
Russell Keith-Magee authored June 10, 2009

Showing 1 changed file with 13 additions and 10 deletions. Show diff stats Hide diff stats

  1. 23  docs/topics/forms/modelforms.txt
23  docs/topics/forms/modelforms.txt
@@ -323,16 +323,19 @@ Since the Author model has only 3 fields, 'name', 'title', and
323 323
     to be empty, and does not provide a default value for the missing fields,
324 324
     any attempt to ``save()`` a ``ModelForm`` with missing fields will fail.
325 325
     To avoid this failure, you must instantiate your model with initial values
326  
-    for the missing, but required fields, or use ``save(commit=False)`` and
327  
-    manually set any extra required fields::
  326
+    for the missing, but required fields::
328 327
 
329  
-        instance = Instance(required_field='value')
330  
-        form = InstanceForm(request.POST, instance=instance)
331  
-        new_instance = form.save()
  328
+        author = Author(title='Mr')
  329
+        form = PartialAuthorForm(request.POST, instance=author)
  330
+        form.save()
332 331
 
333  
-        instance = form.save(commit=False)
334  
-        instance.required_field = 'new value'
335  
-        new_instance = instance.save()
  332
+    Alternatively, you can use ``save(commit=False)`` and manually set
  333
+    any extra required fields::
  334
+
  335
+        form = PartialAuthorForm(request.POST)
  336
+        author = form.save(commit=False)
  337
+        author.title = 'Mr'
  338
+        author.save()
336 339
 
337 340
     See the `section on saving forms`_ for more details on using
338 341
     ``save(commit=False)``.
@@ -563,8 +566,8 @@ number of objects needed::
563 566
     >>> formset.initial
564 567
     [{'id': 1, 'name': u'Charles Baudelaire'}, {'id': 3, 'name': u'Paul Verlaine'}]
565 568
 
566  
-If the value of ``max_num`` is higher than the number of objects returned, up to 
567  
-``extra`` additional blank forms will be added to the formset, so long as the 
  569
+If the value of ``max_num`` is higher than the number of objects returned, up to
  570
+``extra`` additional blank forms will be added to the formset, so long as the
568 571
 total number of forms does not exceed ``max_num``::
569 572
 
570 573
     >>> AuthorFormSet = modelformset_factory(Author, max_num=4, extra=2)

0 notes on commit 6ad26e6

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