我加入:
lawyers = Lawyer.objects.filter(last__iexact=last_name).filter(first__icontains=first_name)
http://swims with.com/search-form/"rel=“nofollow noreferer”> 该网站。
如果你尝试最后名称:阿巴斯和第一名称:Amr告诉你,友好堡有1名校友。
但是,如果你只尝试第一名字,那么它就说,在称为“友好”的数据库中没有律师(显然有律师)。
如果I 更改(last__iexact=last_name)
至(last__icontains=last_name)
之后,找到了最后姓名空白的工件。
但是,有<条码> 最终__icontains=last_name。 如果你寻找“col子”,你也获得“col子”和“wood材”,这不是我想要的东西。
你们是否知道我如何使用<代码>iexact,如果是空白,是否也忽视了这一条?
增 编
这是观点功能:
def search_form(request):
if request.method == POST :
search_form = SearchForm(request.POST)
if search_form.is_valid():
last_name = search_form.cleaned_data[ last_name ]
first_name = search_form.cleaned_data[ first_name ]
lawyers = Lawyer.objects.filter(last__iexact=last_name).filter(first__icontains=first_name)
if len(lawyers)==0:
form = SearchForm()
return render_to_response( not_in_database.html , { last : last_name, first : first_name, form : form})
if len(lawyers)>1:
form = SearchForm(initial={ last_name : last_name})
return render_to_response( more_than_1_match.html , { lawyers : lawyers, last : last_name, first : first_name, form : form})
q_school = Lawyer.objects.filter(last__icontains=last_name).filter(first__icontains=first_name).values_list( school , flat=True)
q_year = Lawyer.objects.filter(last__icontains=last_name).filter(first__icontains=first_name).values_list( year_graduated , flat=True)
lawyers1 = Lawyer.objects.filter(school__iexact=q_school[0]).filter(year_graduated__icontains=q_year[0]).exclude(last__icontains=last_name)
form = SearchForm()
return render_to_response( search_results.html , { lawyers : lawyers1, last : last_name, first : first_name, form : form})
else:
form = SearchForm()
return render_to_response( search_form.html , { form : form, })