On Thu, 2008-12-11 at 20:19 -0800, maeck wrote:
> 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)

Initial for data should be a something that is, or at least behaves
like, a sequence of dictionaries. A queryset is behaves like a sequence,
but the elements of that sequence don't behave like dictionaries
(they're objects -- in this case, Parent objects).

So whilst, "for key in obj:" works when "obj" is a dictionary, it
doesn't work when "obj" is a Django Model subclass (e.g. a Parent).

Since the requirement is to pass in a list of dictionaries, using the
values() method on your inlinedata call will get you a long way there.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to