Last active
March 18, 2022 15:53
-
-
Save PaulSebalu/1c10d3ed0e0647ac769ae833232c340c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Link to repo: https://github.com/PaulSebalu/bookstore | |
# using the interactive shell: "python manage.py shell" | |
from django.db.models import Count | |
from store.models import Author | |
authors=Author.objects.annotate(Count('book')).order_by('-book__count') | |
for author in authors: | |
f"{author.name}. {author.book__count}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment