title: Custom aggregate annotation in Django
body: <p>I have many groups which each has a revision and each revision has some months.</p>
  
  <p>I want to output all the group objects with an annotation.</p>
  
  <p>For each group it should only select the latest revision and then sum all the months.</p>
  
  <p>I'm not sure if it can be done in Django. I tried something like</p>
  
  <pre><code>Group.objects.annotate(
      month_sum=Revision.objects.filter(date__lte=my_date).latest('date').aggregate(Sum('months__amount'))
  )
  </code></pre>
  
  <p>and hoped to get a queryset with all groups which each has a sum <code>month_sum</code>.</p>