Django Queryset: select and prefetch related.
Posted on Sat 19 August 2017 in Django • 1 min read
Today, we will learn more about Django Queryset methods select_related() and prefetch_related(). I decided to write an article after I recommended to a blogger Lucas Magnum.
While I wrote this post I see that a slogan of Lucas Magnum's blog is: (I support this idea with both hands :blush:)
Learning through sharing.
Before you start, you need to know about a problem N+1.
If you just started programming on Django framework, you need to remember:
- select_related - forward relationship
- prefetch_related - reverse relationship
List of links to read:
- Django docs about select_related
- Django docs about prefetch_related
- Of course Lucas Magnum's post
- Advanced usage of prefetch_related
- Solving Performance Problems in the Django ORM