我正在使用django 1.7.1,并试图按照文档使用Prefetch对象,但是我得到了一个名称错误global name 'Prefetch' is not defined。我的查询如下:
prefetch = Observation.objects.prefetch_related(Prefetch('flowers__observations'))我在这里错过了什么?我在任何地方都找不到使用Prefetch对象的示例。
我想使用Prefetch,因为它允许您传递自定义的查询集。我需要过滤来自prefetch_related的结果,而Prefetch对象似乎是最好的方法。
发布于 2015-05-18 20:19:59
您需要Prefetch将其与导入列表一起添加:
from django.db.models import Prefetchhttps://stackoverflow.com/questions/30312098
复制相似问题