Created
April 29, 2020 19:10
-
-
Save susmithagudapati/583fbd219d62a06f1a0dd1b8d8fd3e58 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
# usage of annotation | |
# annotates number of attributes to each product. | |
products = Product.objects.annotate(number_of_attributes=Count('attributes')) | |
products[0].number_of_attributes | |
4 | |
# the other way to define | |
products = Product.objects.annotate(Count('attributes')) | |
products[0].attributes__count | |
4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment