Django 6 · ORM queries
Avoid N+1 queries
Fetch a foreign key in the same query. Use prefetch_related for many-to-many and reverse relations.
Post.objects.select_related("author")
Official Django 6 documentation
Django 6 · ORM queries
Fetch a foreign key in the same query. Use prefetch_related for many-to-many and reverse relations.
Post.objects.select_related("author")
Official Django 6 documentation
Was this page helpful?