On Tue, 2010-10-12 at 20:39 -0700, nathan wrote:
> I have three Models:
>
> Person:
> name = models.CharField(max_length=20)
>
> Item:
> name = models.CharField(max_length=20)
>
> Collection:
> owner = models.ForeignKey(Person)
> items = models.ManyToManyField(Item)
>
> Where each Person has a Collection consisting of several Items.
>
> What I want to do is, on a single page display the contents of the
> database like such:
>
> Person 1
> Item 1
> Item 2
>
> Person 2
> Item 1
>
> etc..
>
> I have absolutely no idea how to create the queries in django to do
> this. I know how to do it with raw sql, just not the best way to do it
> with django. Or how to format the queries and pass them to the
> template. Any suggestions would be most appreciated.
for person in Person.objects.all():
print person
for collection in person.collection_set.all():
for itm in collection.items.all():
print itm
--
regards
Kenneth Gonsalves
--
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.