title: How do I generate and display Django querysets from the results of another queryset?
body: <p>For example, let's say I have the following models:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>I want to list all groups, and for each group list the people in the group.</p>
  
  <p>Group A: Person1, Person2, Person3<br>
  Group B: Person4, Person5, Person6</p>
  
  <p>I get stuck at Group.objects.all(), which will only return a queryset containing the Group objects that I can cycle through in the template. I don't know how to cycle through the people in each group though. Help?</p>
  
  <pre><code>groups = Group.objects.all()
  
  {% for g in groups %}
      g.group_name:
     &lt;&lt; Need an inner loop here to cycle through the people in each group? &gt;&gt;
  {% endfor %}
  </code></pre>