title: django orm and 3 relations
body: <p>I have a problem to transpose my sql request in the  orm.</p>
  
  <p>Well, this my sql request :</p>
  
  <pre><code>SELECT DISTINCT accommodation.id from accommodation
  LEFT JOIN product on product.accommodation_id=accommodation.id
  LEFT JOIN date on date.product_id = product.id
  WHERE date.begin&gt; '2010-08-13';
  </code></pre>
  
  <p>So i want all the accommodations for a period, without doubloon.</p>
  
  <p>My models are like this :</p>
  
  <pre><code>class Accommodation(models.Model):
      ...
  
  class Product(models.Model):
      ...
      accommodation = models.ForeignKey(accommodation)
  
  class Date(models.Model):
      ...
      begin = models.DateField()
      product = models.ForeignKey(Product)
  </code></pre>
  
  <p>So for the moment i do that :</p>
  
  <pre><code>dates = Date.objects.filter(begin__gte=values['start_day'],
  
          ...)
  ...
  accommodations_dict = {}
  
  for date in dates : accommodations_dict[date.product.accommodation.slug] = True
  
  accommodations = Accommodation.objects.filter(slug__in=accommodations_dict.keys())
  </code></pre>
  
  <p>Well, it works, but it's slow, I have a lot of dates.</p>
  
  <p>So I think I can get these accommodations with sql, but I don't know how ?</p>
  
  <p>if you have an idea,
  thanks.</p>