On 8 nov, 16:52, Daniel Roseman <dan...@roseman.org.uk> wrote: > 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.
Note that this also requires replacing the 'question_id' IntegerField in Answer with a 'question' ForeignKey ;) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.