Re: Nested iteration through related models

2010-12-22 Thread Tom Evans
On Tue, Dec 21, 2010 at 9:48 PM, Dopster wrote: > Let's say I have the following models: > > class Group(models.Model): >     group_name = models.CharField(max_length=20) > > class Person(models.Model): >     group = models.ForeignKey(Group) >     name = models.CharField(max_length=50) > > How do

Re: Nested iteration through related models

2010-12-21 Thread Javier Guerra Giraldez
in the view: persons = Person.objects.all().order_by('group') in the template: {% for p in persons %} {% ifchanged p.group %} {{p.group}}: {%endifchanged%} {{p.name}} {% endfor %} -- Javier -- You received this message because you are subscribed to the Google Groups "Django users

Nested iteration through related models

2010-12-21 Thread Dopster
Let's say I have the following models: class Group(models.Model): group_name = models.CharField(max_length=20) class Person(models.Model): group = models.ForeignKey(Group) name = models.CharField(max_length=50) How do I get an output of the following? GroupA: John, Stacy, Pete Group