Ticket #11674: 11674.diff
File 11674.diff, 2.1 KB (added by , 13 years ago) |
---|
-
docs/topics/forms/modelforms.txt
328 328 329 329 If you specify ``fields`` or ``exclude`` when creating a form with 330 330 ``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. 337 334 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 338 342 author = Author(title='Mr') 339 343 form = PartialAuthorForm(request.POST, instance=author) 340 344 form.save() … … 628 632 instance won't be saved to the database and won't be included in the return 629 633 value (``instances``, in the above example). 630 634 635 When fields are missing from the form, for example because they have been 636 excluded, these fields will not be set by the ``save()`` method. You can find 637 more information about this restriction, which also holds for regular 638 ``ModelForms``, and its consequences in section `Using a subset of fields on 639 the form`_ of the ``ModelForms`` documentation. 640 631 641 Pass ``commit=False`` to return the unsaved model instances:: 632 642 633 643 # don't save to the database