当我将feature_name的输入作为newFeature
时,它会给我找到文件夹但是当我给newFeature123
时,它会给我找不到文件夹
在FeatureCache表中,这两个是newFeature123
和newFeature
。这些文件夹名称存在,但它与newFeature匹配,但与newFeature123不匹配。
views.py:
def passReviewerProjFeature(request):
if request.method == 'POST':
feature_name = request.POST['tcrsearch_id']
project_id = request.POST['tcrproject_id']
featureObjectarray=FeatureCache.objects.filter(project=project_id)
for object in featureObjectarray:
print object.name
if feature_name not in str(object.name):
print feature_name
print "not Present"
return render(request,'index.html',{'errmsg':"Folder Not Found"})
else:
return render(request,'index.html',{'errmsg':"Folder Found"})
答案 0 :(得分:1)
在django queryset中查找field lookups。
基本上contains
和icontains
可能就是您要找的地方:
FeatureCache.objects.filter(project__icontains=feature_name, project__exact=project_id)
将执行不区分大小写的查找。像这样:
featureObjectarray=FeatureCache.objects.filter(project__icontains=feature_name, project__exact=project_id)
if featureObjectarray.exists():
return render(request,'index.html',{'errmsg':"Folder Found"})
else:
print feature_name
print "not Present"
return render(request,'index.html',{'errmsg':"Folder Not Found"})