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

More orm queries commands

All orm queries commands · Django 6 cheatsheet

Was this page helpful?