以下代码未返回预期结果:
def getAssignedRoutes( request ):
search = request.POST.get('search', None)
rtgwfSelectRoutes = SelectRoute.objects.exclude(status='rtg_wf_resp').order_by('-created')
if search is not None and len(search.strip()) > 2:
rtgwfSelectRoutes.filter(correlation_id__icontains=search.strip())
return render(request,'select_tool/assignedRoutes.html',{'rtgwfSelectRoutes': rtgwfSelectRoutes})
rtgwfSelectRoutes返回所有记录,而不过滤搜索。怎么了?
答案 0 :(得分:0)
找到了解决方案:当过滤器返回某些内容时,您必须将其分配给变量,例如:
rtgwfSelectRoutes = rtgwfSelectRoutes.filter(correlation_id__icontains=search.strip())
现在它像预期的那样工作;)