Assuming these as django model for the sake of simplcity:
class A(): a = manytomany(\'B\') class B(): b = charfield() z = foreignkey(\'C\') class
You only need one prefetch_related call:
prefetch_related
foo = A.objects.prefetch_related('a__z').get(pk=1)
This will prefetch both tables. In Django 1.7+ you can improve performance by using a Prefetch object, as in koniiiik's answer.
Prefetch