SoFunction
Updated on 2024-11-13

Example of fuzzy query with models in python Django

Example of fuzzy query with models in python Django

Updated July 18, 2019 15:28:08 by gracesyuan
Today I will share a python Django models for fuzzy query example, has a good reference value, I hope to help you. Together follow the editor over to see it

Multiple field fuzzy query, the underscore in the parentheses is a double underscore, the double underscore is preceded by the name of the field, theafter double underliningcan be icontains or contains, the difference is whether the case sensitive, vertical line means or

#Search function
@csrf_exempt#Exempt csrf validation with @csrf_exempt decorator
def search_testCaseApi(request):
  if  == 'POST':
    name = ('task_name')
    updateUser=('task_updateUser')
    if name=="" and updateUser=="":
      obj_all = tnw_test_case_api.(del_flag=0)
    elif name!="" and updateUser=="":
      obj_all = tnw_test_case_api.(del_flag=0,case_name__contains=name)
    elif name=="" and updateUser!="":
      obj_all = tnw_test_case_api.(del_flag=0,update_user__contains=updateUser)
    else:
      obj_all = tnw_test_case_api.(del_flag=0,case_name__contains=name,update_user__contains=updateUser)
    ApiCasesList = []
    for li in obj_all:
      need_interfacename = allFunction().get_interfaceName()
      api_list, api_sum = allFunction().testIDConnect_needid()
      if li.case_module is not None:
        ({
          "testCaseApi_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:
        ({
          "testCaseApi_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,
        })
    # Convert int types to str types using the dumps() method
    ApiCasesList_len = (len(ApiCasesList))
    # Construct a dictionary
    json_data_list = {'rows': ApiCasesList, 'total': ApiCasesList_len}
    # dumps() transforms the dictionary into json form, the
    easyList = (json_data_list)
    # Return the json, the keys in the json key-value pairs need to be consistent with the name of the X in the field="X" of the table in the foreground.)
    return HttpResponse(easyList)

Above this python Django in models for fuzzy query example is all I share with you, I hope to give you a reference, and I hope you support me more.

  • python
  • Django
  • models
  • fuzzy query

Related articles

  • Python Crawler Example - Crawling Meituan Food Data

    This article introduces the Python crawler how to crawl the Mission food data, the text explains in great detail, the code to help you better understand and learn, interested friends can learn about it
    2020-07-07
  • Talking about what the @ symbol means in Python

    @ symbol used as a function of the modifier, you can modify the function in the module or class definition layer, the following article mainly gives you an introduction to the Python @ symbol what is the meaning of the relevant information, the need for friends can refer to the following
    2021-09-09
  • Python Web Crawler Essentials of Beautiful Soup's usage instructions

    In short, Beautiful Soup is a python library, the main function is to crawl data from web pages, Beautiful Soup provides some simple, python-style functions to deal with navigation, searching, modifying the analysis tree and other functions, if you need to refer to the following
    2021-09-09
  • Source code for python design and implementation of the planar point class Point

    This article introduces the python-design and implementation of a planar point class Point, define a planar point class Point, its overloaded operators relational operators, relational operations to the distance from the origin of the coordinates of the distance as a reference, need friends can refer to the following
    2024-05-05
  • Detailed usage of dataset in pytorch

    This article introduces pytorch dataset usage details, when we inherit a Dataset class, we need to rewrite the len method, the method provides the size of the dataset; getitem method, the method supports the index from 0 to len(self), the following take a look at the accompanying code to explain it, I hope that your learning! or work to help
    2022-01-01
  • pytorch commonly used functions of () interpretation

    This article introduces pytorch commonly used functions of () interpretation, with good reference value, I hope to help you. If there is any error or not fully consider the place, look forward to advice!
    2023-02-02
  • Project practice for python asynchronous IO

    This article introduces the python asynchronous IO project practice, the text of the sample code through the introduction of the very detailed, for everyone to learn or work with a certain reference to the value of learning, the need for friends here with the editor to learn together!
    2023-06-06
  • pygame implementation of a similar full of stars game process details

    This article introduces the use of pygame to write a class full of stars game full record, the text of the sample code through the introduction of the very detailed, for everyone's learning or work has a certain reference learning value, the need for friends below with the editorial to learn together!
    2022-09-09
  • Python's approach to preventing deadlocks

    This article introduces the Python method of preventing deadlocks, the text explains very carefully, the code to help you better understand and learn, interested friends can understand the next
    2020-07-07
  • Android sub-packaging MultiDex strategy in detail

    This article introduces the Android sub-packaging MultiDex strategy in detail, with some reference value, the need for friends can understand.
    2017-10-10

Latest Comments