Last active
April 27, 2020 11:22
-
-
Save susmithagudapati/3bb6afe542bb9e95008f1828480d793c 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
# instantiates a queryset and cache is empty. | |
product = Product.objects.get(id=5) | |
# Category object is retrieved from the database at this point | |
# and the results are saved in queryset's cache. | |
product.category | |
# retrieved from the cached results. | |
product.category | |
# callable attributes queries database every sigle time | |
product.categories.all() # query performed using db | |
product.categories.all() # query performed again using db |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment