我对Python感到困惑,如果 我制作了四个输入文字作为搜索过滤器。 在Debug中,我尝试了“ x不是None”或“ x!= None” 但这行不通。 [在请求具有参数的情况下,工作结果良好] [请求没有任何参数时工作不正常] 1
def search(request):
good = request.GET.get("q2")
buyer = request.GET.get("q3")
StartTime = request.GET.get("SD")
EndTime = request.GET.get("ED")
context = {}
if good is not '' or buyer is not '':
if good != '' and buyer != '':
context = Dlyndx.objects.filter(
Q(date__gt=StartTime),Q(date__lte=EndTime),
Q(dlysale__btype__exact=buyer)&Q(dlysale__ptype__exact=good) |
Q(dlybuy__btype__exact=buyer)&Q(dlybuy__ptype__exact=good))
return render_to_response('search.html',{'context':context})
elif good != '' and buyer == '':
context = Dlyndx.objects.filter(
Q(date__gt=StartTime),Q(date__lte=EndTime),
Q(dlysale__ptype__exact=good) |
Q(dlybuy__ptype__exact=good))
return render_to_response('search.html',{'context':context})
else:
context = Dlyndx.objects.filter(
Q(date__gt=StartTime),Q(date__lte=EndTime),
Q(dlysale__btype__exact=buyer) |
Q(dlybuy__btype__exact=buyer)).distinct()
return render_to_response('search.html',{'context':context})
else:
return render(request,"search.html")