0PricingLogin
Django Academy · Lesson

select_related for Foreign Keys

JOIN related rows in one query.

Meet select_related

select_related tells Django to fetch related rows up front in the same query, so loops stop firing extra trips. ⚡

It Uses a JOIN

Under the hood it adds a SQL JOIN, pulling the parent and its related row together in one efficient round trip.

All lessons in this course

  1. Spotting the N+1 Problem
  2. select_related for Foreign Keys
  3. prefetch_related for M2M
  4. Profiling with Debug Toolbar
← Back to Django Academy