The global name "Prefetch" is undefined

I am using django 1.7.1 and trying to use a Prefetch object according to docs But I am getting a name error global name 'Prefetch' is not defined. My query looks like this:

  prefetch = Observation.objects.prefetch_related(Prefetch('flowers__observations'))

What am I missing here? I cannot find any examples anywhere using the Prefetch object.

I want to use Prefetch because it allows you to pass a custom request. I need to filter the results from prefetch_related, and Prefetch objects are the best way to do this.

+4
source share
1 answer

You need to importPrefetch Add this along with your import list:

from django.db.models import Prefetch
+7
source

All Articles