title: Mutliple fields in the where clause of a QuerySet
body: <p>In a e-shop application I have a model for storing history of order processing:</p>
  
  <pre><code>class OrderStatusHistory(models.Model):
      order = models.ForeignKey(Order, related_name='status_history')
      status = models.IntegerField()
      date = models.DateTimeField(auto_now_add=True)
  </code></pre>
  
  <p>Now I want to get most recent status for each order. In pure SQL I can do this in a single query:</p>
  
  <pre><code>select * from order_orderstatushistory where (order_id, date) in (select order_id, max(date) from order_orderstatushistory group by order_id)
  </code></pre>
  
  <p>What is the best way do this in Django?</p>
  
  <p>I have two options. The first is:</p>
  
  <pre><code># Get the most recent status change date for each order
  v = Order.objects.annotate(Max('status_history__date')).values_list('id', 'status_history__date__max')
  
  # Get OrderStatusHistory objects
  hist = OrderStatusHistory.objects.extra(where=['(order_id, date) IN %s'], params=[tuple(v)])
  </code></pre>
  
  <p>And the second:</p>
  
  <pre><code>hist = OrderStatusHistory.objects.extra(where=['(order_id, date) IN (select order_id, max(date) from order_orderstatushistory group by order_id)'])
  </code></pre>
  
  <p>The first option is pure Django, but results in 2 database queries and a large list of parameters passed from Django to database engine.</p>
  
  <p>The second option requires to put SQL code directly into my application, but I'd like to avoid this.</p>
  
  <p>Is there equivalent of <code>where (order_id, date) in (select ...)</code> in Django?</p>