Added support for specifying initial values to model formsets and inline formsets.

This make them consistent with the similar capability of regular
formsets. Thanks to simon29 form the report and to Claude Paroz for the
patch.

Fixes #14574.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17373 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Ramiro Morales 2012-01-15 01:36:14 +00:00
parent 4e29b70b9d
commit e308cfc0e1
6 changed files with 48 additions and 3 deletions

View file

@ -53,6 +53,8 @@ Formsets can also be indexed into, which returns the corresponding form. If you
override ``__iter__``, you will need to also override ``__getitem__`` to have
matching behavior.
.. _formsets-initial-data:
Using initial data with a formset
---------------------------------

View file

@ -617,6 +617,17 @@ exclude::
>>> AuthorFormSet = modelformset_factory(Author, exclude=('birth_date',))
Providing initial values
------------------------
.. versionadded:: 1.4
As with regular formsets, it is possible to :ref:`specify initial data
<formsets-initial-data>` for forms in the formset by specifying an ``initial``
parameter when instantiating the model formset class returned by
``modelformset_factory``. However, with model formsets the initial values only
apply to extra forms, those which are not bound to an existing object instance.
.. _saving-objects-in-the-formset:
Saving objects in the formset