Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed 11674 -- Clarified docs on excluded fields of ModelForms.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16875 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4f109fcbfff87f1bdfc64fb3748ccff8bac297f5 1 parent 4f9cf2e
Paul McMillan authored September 22, 2011

Showing 1 changed file with 17 additions and 7 deletions. Show diff stats Hide diff stats

  1. 24  docs/topics/forms/modelforms.txt
24  docs/topics/forms/modelforms.txt
@@ -331,13 +331,17 @@ Since the Author model has only 3 fields, 'name', 'title', and
331 331
 .. note::
332 332
 
333 333
     If you specify ``fields`` or ``exclude`` when creating a form with
334  
-    ``ModelForm``, then the fields that are not in the resulting form will not
335  
-    be set by the form's ``save()`` method. Django will prevent any attempt to
336  
-    save an incomplete model, so if the model does not allow the missing fields
337  
-    to be empty, and does not provide a default value for the missing fields,
338  
-    any attempt to ``save()`` a ``ModelForm`` with missing fields will fail.
339  
-    To avoid this failure, you must instantiate your model with initial values
340  
-    for the missing, but required fields::
  334
+    ``ModelForm``, then the fields that are not in the resulting form
  335
+    will not be set by the form's ``save()`` method. Also, if you
  336
+    manually add the excluded fields back to the form, they will not
  337
+    be initialized from the model instance.
  338
+
  339
+    Django will prevent any attempt to save an incomplete model, so if
  340
+    the model does not allow the missing fields to be empty, and does
  341
+    not provide a default value for the missing fields, any attempt to
  342
+    ``save()`` a ``ModelForm`` with missing fields will fail.  To
  343
+    avoid this failure, you must instantiate your model with initial
  344
+    values for the missing, but required fields::
341 345
 
342 346
         author = Author(title='Mr')
343 347
         form = PartialAuthorForm(request.POST, instance=author)
@@ -632,6 +636,12 @@ database. If a given instance's data didn't change in the bound data, the
632 636
 instance won't be saved to the database and won't be included in the return
633 637
 value (``instances``, in the above example).
634 638
 
  639
+When fields are missing from the form (for example because they have
  640
+been excluded), these fields will not be set by the ``save()``
  641
+method. You can find more information about this restriction, which
  642
+also holds for regular ``ModelForms``, in `Using a subset of fields on
  643
+the form`_.
  644
+
635 645
 Pass ``commit=False`` to return the unsaved model instances::
636 646
 
637 647
     # don't save to the database

0 notes on commit 4f109fc

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