The example below is a snippet from a view where I use a form to show
'Parent' and a formset to show its 'Children'.
If I get the children as a queryset and pass it on to the formsets
initial property, it errors out with: 'Parent' object is not iterable
InlineFormSet = formset_factory(InlineForm)
data = Parent.objects.get(id = data_id)
form = ParentForm(instance=data)
inlinedata = Child.objects.filter(parent_id = data_id)
inlineform = InlineChildFormSet(initial=inlinedata)
However, the following works (same data, just a list of dicts):
InlineFormSet = formset_factory(InlineForm)
data = Parent.objects.get(id = data_id)
form = ParentForm(instance=data)
inlinedata = [ {'a':10, 'b':20}
{'a':11, 'b':21}
]
inlineform = InlineChildFormSet(initial=inlinedata)
What am I missing in the first example?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---