mirror of
https://github.com/django/django.git
synced 2025-06-05 11:39:13 +00:00
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
This commit is contained in:
parent
484ef94587
commit
4d30be23dc
@ -1923,11 +1923,22 @@ of the model fields:
|
|||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
If you specify ``fields`` when creating a form with ``form_for_model()``,
|
If you specify ``fields`` when creating a form with ``form_for_model()``,
|
||||||
make sure that the fields that are *not* specified can provide default
|
then the fields that are *not* specified will not be set by the form's
|
||||||
values, or are allowed to have a value of ``None``. If a field isn't
|
``save()`` method. Django will prevent any attempt to save an incomplete
|
||||||
specified on a form, the object created from the form can't provide
|
model, so if the model does not allow the missing fields to be empty, and
|
||||||
a value for that attribute, which will prevent the new instance from
|
does not provide a default value for the missing fields, any attempt to
|
||||||
being saved.
|
``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
|
Overriding the default field types
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
Loading…
x
Reference in New Issue
Block a user