Django

Code

Changeset 6409

Show
Ignore:
Timestamp:
09/23/07 00:59:12 (1 year ago)
Author:
russellm
Message:

Fixed #5364 -- Clarified the warning regarding saving form_for_model forms with missing fields. Thanks to PhilR for the initial draft.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/newforms.txt

    r6357 r6409  
    19241924 
    19251925    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`_ 
    19311942 
    19321943Overriding the default field types