title: How to filter joined models in Django?
body: <p>I have the following models:</p>
  
  <pre><code>class Street(models.Model):
      name = models.CharField(max_length=40)
  
  class House(models.Model):
      street = models.ForeignKey(Street, models.PROTECT)
      number = models.CharField(max_length=10)
  
      class Meta:
          unique_together = ('street', 'number')
  
  class Room(models.Model):
      house = models.ForeignKey(House, models.PROTECT)
      number = models.CharField(max_length=10)
  
      class Meta:
          unique_together = ('house', 'number')
  </code></pre>
  
  <p>I already know the ID of a <code>Street</code> and would like to get all the rooms of all the houses in that street. In SQL that is easy:</p>
  
  <pre><code>SELECT *
  FROM room JOIN house ON house.id = room.house_id
  WHERE house.street_id = xyz;
  </code></pre>
  
  <p>Now how do I do this in Django? I tried</p>
  
  <pre><code>Room.objects.select_related('house').filter(street=xyz)
  </code></pre>
  
  <p>But I get an exception saying I can't access this field:</p>
  
  <pre><code>django.core.exceptions.FieldError: Cannot resolve keyword 'street' into field. Choices are: house, house_id, id, number
  </code></pre>
  
  <p>Because of the amounts of data I am facing, I would really like to be able to join and filter using a single query! When giving up one or the other, I would have to resort to either making multiple queries or filtering in Python, both of which are inherently inefficient. An alternative would be raw queries, I guess...</p>