title: Django joining 2 tables which has 2 join conditions
body: <p>I have 2 tables say A and B</p>
  
  <pre><code>class A(models.Model):
    A_val= models.DecimalField(max_digits=4, decimal_places=0)
    A_name= models.CharField(max_length=32, blank=True)
    A_type= models.CharField(max_length=32, blank=True)
    unique_together(A_val,A_name)
  
   class B(models.Model):
      A_val=models.ForeignKey(A)
      A_name=models.ForeignKey(A)
  </code></pre>
  
  <p>Now i want </p>
  
  <pre><code>select * from B,A where A.A_val=B.A_val and A.A_name=B.B_name and A_type="typename"
  </code></pre>
  
  <p>I did the following as told by miki725 to achieve this </p>
  
  <pre><code>B.objects.filter(A_name__A_type='type_name').select_related('A_name', 'A_val')
  </code></pre>
  
  <p>But this is equivalent to </p>
  
  <pre><code>select * from B,A where A.A_name=B.B_name and A_type="typename"
  </code></pre>
  
  <p>It ignores <strong>A.A_val=B.A_val</strong> . I want the join to be based on all 3 conditions. How can i do this</p>