如何使用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)
答案 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