Ticket #11674: 11674.diff

File 11674.diff, 2.1 KB (added by Pieter Swinkels, 13 years ago)

changes to the documentation

  • docs/topics/forms/modelforms.txt

     
    328328
    329329    If you specify ``fields`` or ``exclude`` when creating a form with
    330330    ``ModelForm``, then the fields that are not in the resulting form will not
    331     be set by the form's ``save()`` method. Django will prevent any attempt to
    332     save an incomplete model, so if the model does not allow the missing fields
    333     to be empty, and does not provide a default value for the missing fields,
    334     any attempt to ``save()`` a ``ModelForm`` with missing fields will fail.
    335     To avoid this failure, you must instantiate your model with initial values
    336     for the missing, but required fields::
     331    be set by the form's ``save()`` method. Also, should you manually add the
     332    excluded fields back to the form, they will not be initialized from the
     333    model instance.
    337334
     335    Regarding the first remark, Django will prevent any attempt to save an
     336    incomplete model, so if the model does not allow the missing fields to be
     337    empty, and does not provide a default value for the missing fields, any
     338    attempt  to ``save()`` a ``ModelForm`` with missing fields will fail.  To
     339    avoid this failure, you must instantiate your model with initial values for
     340    the missing, but required fields::
     341
    338342        author = Author(title='Mr')
    339343        form = PartialAuthorForm(request.POST, instance=author)
    340344        form.save()
     
    628632instance won't be saved to the database and won't be included in the return
    629633value (``instances``, in the above example).
    630634
     635When fields are missing from the form, for example because they have been
     636excluded, these fields will not be set by the ``save()`` method. You can find
     637more information about this restriction, which also holds for regular
     638``ModelForms``, and its consequences in section `Using a subset of fields on
     639the form`_ of the ``ModelForms`` documentation.
     640
    631641Pass ``commit=False`` to return the unsaved model instances::
    632642
    633643    # don't save to the database
Back to Top