title: Django Inner Join Queryset
body: <p>I'm working with Django and I need to do a queryset using two inner joins. </p>
  
  <p>I have three models A, B, and C and I want to do a query like the following in psql:</p>
  
  <pre><code>SELECT DISTINCT a FROM A
  INNER JOIN B ON B.a_id = A.id
  INNER JOIN C ON C.b_id = B.id;
  </code></pre>
  
  <p>Models: (only included relevant fields)</p>
  
  <pre><code>class A(models.Model):
      id = models.IntegerField(primary_key=True)
  
  class B(models.Model):
      id = models.IntegerField(primary_key=True)
      a = models.ForeignKey(A, null=True, blank=True,on_delete=models.SET_NULL)
  
  class C(models.Model):
      b = models.ForeignKey(B, null=True, on_delete=models.SET_NULL)   
  </code></pre>
  
  <p>So everything in C links back to one thing in B and everything in B links back to one thing in A. I want to try and get all the distinct elements in A that have something in C.</p>
  
  <p>How do I do this using django queryset? Thanks.</p>