Combining multiple aggregations with annotate() will yield the wrong results 
<https://code.djangoproject.com/ticket/10060>, as multiple tables are cross 
joined. Due to the use of LEFT OUTER JOIN, duplicate records will be 
generated if some of the joined tables contain more records than the others

The Count 
<https://docs.djangoproject.com/en/1.9/ref/models/querysets/#django.db.models.Count>
 aggregate 
has a distinct parameter that may help:

q = Book.objects.annotate(Count('authors', distinct=True), Count('chapters', 
distinct=True))

Why not "distinct=True" to use in Sum?

q = Book.objects.annotate(Sum('val_a', distinct=True), Sum('val_b', 
distinct=True))

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/fab53843-6eb7-49a7-9036-68e80343425f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to