For example, 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)
I want to list all the groups, and for each group a list of people in the group.
Group A: Person1, Person2, Person3
Group B: Person4, Person5, Person6
I am stuck in Group.objects.all (), which will only return a query containing Group objects that I can scroll in the template. However, I do not know how to get through the people in each group. Help?
groups = Group.objects.all() {% for g in groups %} g.group_name: << Need an inner loop here to cycle through the people in each group? >> {% endfor %}
source share