title: Django: how to annotate queryset with count of filtered ForeignKey field?
body: <p>Django novice question :)</p>
  
  <p>I have the following models - each review is for a product, and each product has a department: </p>
  
  <pre><code>class Department(models.Model):
      code = models.CharField(max_length=16)
  class Product(models.Model):
      id = models.CharField(max_length=40, primary_key=True, db_index=True)
      dept = models.ForeignKey(Department, null=True, blank=True, db_index=True)
  class Review(models.Model):
      review_id = models.CharField(max_length=32, primary_key=True, db_index=True) 
      product = models.ForeignKey(Product, db_index=True) 
      time = models.DateTimeField(db_index=True) 
  </code></pre>
  
  <p>I'd like to make a Django query for a date range (2012-01-01 to 2012-01-08) and return a list of all departments, annotated with department ID, and the number of products from that department that were reviewed during that date range. </p>
  
  <p>This is frying my brain a bit :)</p>
  
  <p>I can get all the reviews for a time range: </p>
  
  <pre><code> reviews = Review.filter(time__range=["2012-01-01", "2012-01-08"])
  </code></pre>
  
  <p>Then I guess each review has a product field, and each of those products has a department code. But how can I group them by product and code, with counts and department IDs?</p>
  
  <p>Alternatively, is it best to request the departments, and then annotate them with product counts, somehow? </p>