pythonDjango中models進(jìn)行模糊查詢的示例-創(chuàng)新互聯(lián)

多個(gè)字段模糊查詢, 括號(hào)中的下劃線是雙下劃線,雙下劃線前是字段名,雙下劃線后可以是icontains或contains,區(qū)別是是否大小寫(xiě)敏感,豎線是或的意思

10年積累的成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)制作后付款的網(wǎng)站建設(shè)流程,更有肅州免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
#搜索功能
@csrf_exempt#使用@csrf_exempt裝飾器,免除csrf驗(yàn)證
def search_testCaseApi(request):
  if request.method == 'POST':
    name = request.POST.get('task_name')
    updateUser=request.POST.get('task_updateUser')
    if name=="" and updateUser=="":
      obj_all = tnw_test_case_api.objects.filter(del_flag=0)
    elif name!="" and updateUser=="":
      obj_all = tnw_test_case_api.objects.filter(del_flag=0,case_name__contains=name)
    elif name=="" and updateUser!="":
      obj_all = tnw_test_case_api.objects.filter(del_flag=0,update_user__contains=updateUser)
    else:
      obj_all = tnw_test_case_api.objects.filter(del_flag=0,case_name__contains=name,update_user__contains=updateUser)
    ApiCasesList = []
    for li in obj_all:
      need_interfacename = allFunction().get_interfaceName(li.id)
      api_list, api_sum = allFunction().testIDConnect_needid(li.id)
      if li.case_module is not None:
        ApiCasesList.append({
          "testCaseApi_id": li.id,
          "testCaseApi_name": li.case_name,
          "testCaseApi_sum": api_sum,
          "testCaseApi_version": li.case_version,
          "testCaseApi_module": li.case_module,
          "testCaseApi_need_interfacename": need_interfacename,
          "testCaseApi_createTime": str(li.create_time),
          "testCaseApi_updateTime": str(li.update_time),
          "testCaseApi_updateUser": li.update_user,
        })
      else:
        ApiCasesList.append({
          "testCaseApi_id": li.id,
          "testCaseApi_name": li.case_name,
          "testCaseApi_sum": 1,
          "testCaseApi_version": li.case_version,
          "testCaseApi_module": li.case_module,
          "testCaseApi_need_interfacename": need_interfacename,
          "testCaseApi_createTime": str(li.create_time),
          "testCaseApi_updateTime": str(li.update_time),
          "testCaseApi_updateUser": li.update_user,
        })
    # 將int類(lèi)型使用dumps()方法轉(zhuǎn)為str類(lèi)型
    ApiCasesList_len = json.dumps(len(ApiCasesList))
    # 構(gòu)造一個(gè)字典
    json_data_list = {'rows': ApiCasesList, 'total': ApiCasesList_len}
    # dumps()將字典轉(zhuǎn)變?yōu)閖son形式,
    easyList = json.dumps(json_data_list)
    # 將json返回去,json的鍵值對(duì)中的鍵需要與前臺(tái)的表格field=“X”中的X名稱(chēng)保持一致)
    return HttpResponse(easyList)

文章名稱(chēng):pythonDjango中models進(jìn)行模糊查詢的示例-創(chuàng)新互聯(lián)
本文路徑:http://bm7419.com/article40/dgoheo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、手機(jī)網(wǎng)站建設(shè)、服務(wù)器托管網(wǎng)頁(yè)設(shè)計(jì)公司、Google、全網(wǎng)營(yíng)銷(xiāo)推廣

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁(yè)設(shè)計(jì)