#12213: Initial data and addition queryset_filter for formset from
inlineformset_factory
---------------------------------+------------------------------------------
Reporter: ramusus | Owner: nobody
Status: new | Milestone:
Component: Forms | Version: 1.1
Resolution: | Keywords:
Stage: Unreviewed | Has_patch: 1
Needs_docs: 0 | Needs_tests: 1
Needs_better_patch: 0 |
---------------------------------+------------------------------------------
Changes (by lorochka85):
* component: Uncategorized => Forms
Comment:
Queryset support was added to !BaseInlineFormSet (not initial though) in
the development version and, imho, is better than dealing with filters.
For initial, adding it as an extra argument to !BaseInlineFormset and then
passing to the super's {{{ __init__ }}} does the job.
However, it gets a little bit confusing when one tries to pass both
initial and queryset to ether !BaseInlineFormSet or !BaseModelFormSet. For
example, you have something like:
{{{
formset = BaseModelFormSet(...,
queryset=some_qs,
initial=[{'field1': 'f1value1', 'field2':
'f2value1'},
{'field1': 'f1value2', 'field2':
'f2value2'}],
)
}}}
then values for field1 and field2 for the first 2 items in some_qs will
get overriden with values in initial. In order for the formset to display
first data from the queryset and then extra forms with values from
initial, your initial should look something like:
{{{
initial = [{} for i in range(0, some_qs.count())] +
[{'field1': 'f1value1', 'field2': 'f2value1'},
{'field1': 'f1value2', 'field2': 'f2value2'}]
}}}
...Having said all that, there is a nice little comment about instance and
initial in {{{ BaseModelForm.__init__ }}}:
[http://code.djangoproject.com/browser/django/trunk/django/forms/models.py#L228]
{{{
# if initial was provided, it should override the values from instance
}}}
I suppose this is valid for formsets as well. Should that be documented
somewhere?
Now, in terms of use cases for initial on InlineFormSet, there is one by
Nathan in this thread: [http://groups.google.ru/group/django-
developers/browse_thread/thread/73af9e58bd7626a8/e307d4865759a26e]
--
Ticket URL: <http://code.djangoproject.com/ticket/12213#comment:3>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.