4👍
✅
You should .prefetch_related(..)
[Django-doc] the related Choice
s. Then Django will make an extra query to fetch the Choice
s all at once, and do the JOIN at the Python/Django level.
def index(request):
return render(
request,
'polls/index.html',
{'questions': Question.objects.prefetch_related('choice_set')}
)
Source:stackexchange.com