Last active
March 18, 2022 15:53
-
-
Save PaulSebalu/3c8a3a5eb88d1fa80e68942fcce757af 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 Prefetch | |
from store.models import Author | |
authors=Author.objects.prefetch_related(Prefetch("book_set")).all() | |
for author in authors: | |
f"{author.name}:{author.book_set.all()}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment