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.
You need to import Prefetch
Add this along with your list of imports:
from django.db.models import Prefetch
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With