Author: russellm
Date: 2007-09-23 00:59:12 -0500 (Sun, 23 Sep 2007)
New Revision: 6409
Modified:
django/trunk/docs/newforms.txt
Log:
Fixed #5364 -- Clarified the warning regarding saving form_for_model forms with
missing fields. Thanks to PhilR for the initial draft.
Modified: django/trunk/docs/newforms.txt
===================================================================
--- django/trunk/docs/newforms.txt 2007-09-23 04:56:19 UTC (rev 6408)
+++ django/trunk/docs/newforms.txt 2007-09-23 05:59:12 UTC (rev 6409)
@@ -1923,12 +1923,23 @@
.. note::
If you specify ``fields`` when creating a form with ``form_for_model()``,
- make sure that the fields that are *not* specified can provide default
- values, or are allowed to have a value of ``None``. If a field isn't
- specified on a form, the object created from the form can't provide
- a value for that attribute, which will prevent the new instance from
- being saved.
+ then the fields that are *not* specified will not be set by the form's
+ ``save()`` method. Django will prevent any attempt to save an incomplete
+ model, so if the model does not allow the missing fields to be empty, and
+ does not provide a default value for the missing fields, any attempt to
+ ``save()`` a ``form_for_model`` with missing fields will fail. To avoid
+ this failure, you must use ``save(commit=False)`` and manually set any
+ extra required fields::
+ instance = form.save(commit=False)
+ instance.required_field = 'new value'
+ instance.save()
+
+ See the `section on saving forms`_ for more details on using
+ ``save(commit=False)``.
+
+.. _section on saving forms: `The save() method`_
+
Overriding the default field types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---