title: Django generic relation problem
body: <p>I'm having problems coming up with a filter in one of my views. I'm creating a site with blog entries, news articles, and reviews. The entries and articles have generic relations with the reviews, because the reviews can tag either of them. What I'm trying to do is to sort the entries/articles based on <em>the sum of the ratings</em> of reviews <em>newer than a certain date</em>.</p>
  
  <p>Here are the simplified models:</p>
  
  <pre><code>class Entry(models.Model):
      name = models.CharField(max_length=50)
      reviews = generic.GenericRelation(Review)
  
  class Article(models.Model):
      name = models.CharField(max_length=50)
      reviews = generic.GenericRelation(Review)
  
  class Review(models.Model):
      rating = models.IntegerField()
      content_type = models.ForeignKey(ContentType)
      object_id = models.PositiveIntegerField()
      target = generic.GenericForeignKey('content_type', 'object_id')
      timestamp = models.DateTimeField(auto_now_add=True)
  </code></pre>
  
  <p>So, given that I needed to find a sum, I tried using annotate and aggregate, but I ran into two problems. The first one is that apparently generic relations and annotations don't work nicely together: <a href="https://code.djangoproject.com/ticket/10461" rel="nofollow">https://code.djangoproject.com/ticket/10461</a>. The second issue is that I don't think it's possible to only sum part of the reviews (in this case, with timestamp__gte=datetime.now()). Am I doing this the wrong way?</p>
  
  <p>I also thought about doing this the other way around:</p>
  
  <pre><code>Review.filter(timestamp__gte=datetime.now(), target__in=something).aggregate(Sum('rating'))
  </code></pre>
  
  <p>But since I'm trying to order the reviews based on this, don't I need to start with Review.something so I can use order_by?</p>
  
  <p>Thanks.</p>