以Dan Herrar的示例为例 在此处输入代码
from django.db.models import Q
user_pk = 1
category_pk = 1 #some times None
f = Q( user__pk = user_pk, date=now() )
if category_pk is not None:
f &= Q( category__pk = category_pk )
todays_items = Item.objects.filter( f )
我正在构建一个庞大的过滤器链(我宁愿不这样做),所以我有... 在此处输入代码
from django.db.models import Q
f = Q(availability_text=this)
if 'cabins' in request.POST:
cabins = request.POST['cabins']
if cabins != "0" and cabins != "":
c = cabins
c = int(c)
f &= Q(cabins=c)
if 'thruster' in request.POST:
thruster = request.POST['thruster']
if thruster != 0:
t = 1
f &= Q(thruster=t)
等等等
这是f试验的结果
(AND:('availability_text',''),('bow_thruster',1))
但我明白了
“要解压的值太多”
wm = Boat.objects.filter(name=x).filter( f )[:1].get()
这令人困惑,因为我正在处理4个列表,这是第3次迭代,在第1或第2迭代中没有错误
我们将不胜感激任何见识