Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

global name 'Prefetch' is not defined

Tags:

django

I am using django 1.7.1 and trying to use the Prefetch object as per the docs But I get 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 it a custom queryset. I need to filter the results from prefetch_related, and the Prefetch objects seems like the best way to do it.

like image 465
user2213295 Avatar asked May 18 '15 20:05

user2213295


1 Answers

You need to import Prefetch Add this along with your list of imports:

from django.db.models import Prefetch
like image 63
karthikr Avatar answered Nov 15 '22 04:11

karthikr