Created
April 29, 2020 19:09
-
-
Save susmithagudapati/dc9623af026729453a5b4a7735aa0f0c 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
# basic usage of aggregation | |
# Max price of all products. | |
from django.db.models import Max | |
Product.objects.all().aggregate(Max('price')) | |
{'price__max': 70.15} | |
# Average view count across all products. | |
from django.db.models import Avg | |
Product.objects.all().aggregate(Avg('view_count')) | |
{'view_count__avg': 10} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment