title: What's the difference between select_related and prefetch_related in Django ORM?
body: <p>In Django doc,</p>
  <blockquote>
  <p><a href="https://docs.djangoproject.com/en/stable/ref/models/querysets/#select-related" rel="noreferrer"><code>select_related()</code></a> &quot;follows&quot; foreign-key relationships, selecting additional related-object data when it executes its query.</p>
  <p><a href="https://docs.djangoproject.com/en/stable/ref/models/querysets/#prefetch-related" rel="noreferrer"><code>prefetch_related()</code></a> does a separate lookup for each relationship, and does the &quot;joining&quot; in Python.</p>
  </blockquote>
  <p>What does it mean by &quot;doing the joining in python&quot;? Can someone illustrate with an example?</p>
  <p>My understanding is that for foreign key relationship, use <code>select_related</code>; and for M2M relationship, use <code>prefetch_related</code>. Is this correct?</p>