如何在表usidng django查询中搜索匹配的名称

时间:2014-05-01 12:13:42

标签: django

如何使用django查询匹配表中的测试用例名称并显示相关名称

class TestcaseCache(models.Model):
    name = models.CharField(max_length=60)
    package_name = models.CharField(max_length=100)

Views.py

def testSearch(request):
    print"in tets search"
    search_test_object=""
    if request.POST:
        print "in form post"
        searchText = request.POST.get('Searchbox')
        print  searchText
        search_test_object=TestcaseCache.objects.all().filter(name__contains=searchText)

1 个答案:

答案 0 :(得分:0)

试试这个 -

    def testSearch(request):
        if request.POST:
            searchText = request.POST.get('Searchbox')
            print  searchText
            test_case_name_list=TestcaseCache.objects.filter(name__contains=searchText).values_list('name',flat=True)
            for test_case_name in test_case_name_list:
                 print test_case_name