Commit 922aed54 authored by Russell Keith-Magee's avatar Russell Keith-Magee
Browse files

[1.0.X] Fixed #10845 -- Clarified the examples for using ModelForms with...

[1.0.X] Fixed #10845 -- Clarified the examples for using ModelForms with fields or exclude specified. Thanks to Andrew Durdin for the suggestion.

Merge of r10972 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10975 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 383c46dc
Loading
Loading
Loading
Loading
+13 −10
Original line number Diff line number Diff line
@@ -318,16 +318,19 @@ Since the Author model has only 3 fields, 'name', 'title', and
    to be empty, and does not provide a default value for the missing fields,
    any attempt to ``save()`` a ``ModelForm`` with missing fields will fail.
    To avoid this failure, you must instantiate your model with initial values
    for the missing, but required fields, or use ``save(commit=False)`` and
    manually set any extra required fields::
    for the missing, but required fields::

        instance = Instance(required_field='value')
        form = InstanceForm(request.POST, instance=instance)
        new_instance = form.save()
        author = Author(title='Mr')
        form = PartialAuthorForm(request.POST, instance=author)
        form.save()

        instance = form.save(commit=False)
        instance.required_field = 'new value'
        new_instance = instance.save()
    Alternatively, you can use ``save(commit=False)`` and manually set
    any extra required fields::

        form = PartialAuthorForm(request.POST)
        author = form.save(commit=False)
        author.title = 'Mr'
        author.save()

    See the `section on saving forms`_ for more details on using
    ``save(commit=False)``.