Created
April 29, 2020 19:46
-
-
Save susmithagudapati/210f112d084287d8dc6290aedd8988b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models import Avg, Count | |
# first annotates each product with number of attributes, | |
# and then aggregates the average number of authors using the annotated attribute | |
Product.objects.annotate(num_attributes=Count('attributes')).aggregate(Avg('num_attributes')) | |
{'num_authors__avg': 3.46} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment