2014-05-12 40 views
0

這裏的時候,我給輸入FEATURE_NAME爲newFeature,它給我文件夾中找到,但是當我給newFeature123,它給了我未找到文件夾如何比比與數據庫對象

在功能緩存表中這兩個是newFeature123和輸入字符串newFeature。這些文件夾名稱存在,但與newFeature匹配,但不與newFeature123匹配。

views.py:在Django的queryset

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"}) 

回答

1

查找field lookups

基本上containsicontains可能是你在找什麼:

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"})