Django: implementing JOIN using Django ORM?

This is exactly what select_related() does. The only gotcha is that
you have to start with the Answer model, rather than Question, but the
result is the same:

answers = Answer.objects.filter(question_id=1).select_related() 

Now each answer object has a pre-fetched ‘question’ attribute, and
accessing it won’t hit the db again.

Leave a Comment