title: Querying multiple models and putting results in a table
body: <p>I've got these models:</p>
  
  <pre><code>class League(models.Model):
      ...
  
  class Game(models.Model):
      league = models.ForeignKey(League, related_name='games')
      ...
  
  class Competitor(models.Model):
      user = models.ForeignKey(User, related_name='competitors')
      game = models.ForeignKey(Game, related_name='competitors')
      points = models.CharField(max_length=50, blank=True)
      ...
  </code></pre>
  
  <p>And I want to make a League-score-table in my template:</p>
  
  <pre><code>      | Game1 | Game2 | Game3 | Tot
  Comp1 |       |       |   8   |  8
  Comp2 |   5   |       |   1   |  6
  Comp3 |       |   4   |   3   |  7
  </code></pre>
  
  <p>But I can't figure out how to make these kind of queries in the view. I get that I can get the Games of a League:</p>
  
  <pre><code>l = get_object_or_404(League, pk=id) 
  g = l.games
  </code></pre>
  
  <p>And put it in the table header like this: </p>
  
  <pre><code>{% for game in g %}
  &lt;th&gt;{{ game.name}}&lt;/th&gt;
  {% endfor %}
  </code></pre>
  
  <p>But how do I get the list of distinct competitors for a League of games? Even if they have only played one game in the league.</p>
  
  <p>And how to I iterate the competitors over the games to get the points? 
  What methods should I look into here? Or is it a better way to structure this?</p>