Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #5364 -- Clarified the warning regarding saving form_for_model …

…forms with missing fields. Thanks to PhilR for the initial draft.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6409 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4d30be23dcfc185ff56fb4bbf8ef77f5f47ade53 1 parent 484ef94
Russell Keith-Magee authored

Showing 1 changed file with 16 additions and 5 deletions. Show diff stats Hide diff stats

  1. 21  docs/newforms.txt
21  docs/newforms.txt
@@ -1923,11 +1923,22 @@ of the model fields:
1923 1923
 .. note::
1924 1924
 
1925 1925
     If you specify ``fields`` when creating a form with ``form_for_model()``,
1926  
-    make sure that the fields that are *not* specified can provide default
1927  
-    values, or are allowed to have a value of ``None``. If a field isn't
1928  
-    specified on a form, the object created from the form can't provide
1929  
-    a value for that attribute, which will prevent the new instance from
1930  
-    being saved.
  1926
+    then the fields that are *not* specified will not be set by the form's
  1927
+    ``save()`` method. Django will prevent any attempt to save an incomplete
  1928
+    model, so if the model does not allow the missing fields to be empty, and
  1929
+    does not provide a default value for the missing fields, any attempt to
  1930
+    ``save()`` a ``form_for_model`` with missing fields will fail. To avoid
  1931
+    this failure, you must use ``save(commit=False)`` and manually set any
  1932
+    extra required fields::
  1933
+
  1934
+        instance = form.save(commit=False)
  1935
+        instance.required_field = 'new value'
  1936
+        instance.save()
  1937
+
  1938
+    See the `section on saving forms`_ for more details on using
  1939
+    ``save(commit=False)``.
  1940
+
  1941
+.. _section on saving forms: `The save() method`_
1931 1942
 
1932 1943
 Overriding the default field types
1933 1944
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 notes on commit 4d30be2

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