zoukankan      html  css  js  c++  java
  • django使用search_fields报错

    django使用search_fields报错(in get_lookup_constraint)

    FieldError at /api/workorder/order/

    Related Field got invalid lookup: icontains
    
    Request Method: GET
    Request URL: http://127.0.0.1:8000/api/workorder/order/?search=1
    Django Version: 2.0
    Exception Type: FieldError
    Exception Value: Related Field got invalid lookup: icontains
    Exception Location: C:UsersWMAppDataLocalProgramsPythonPython36libsite-packagesdjangodbmodelssqlquery.py in build_lookup, line 1075
    Python Executable: C:UsersWMAppDataLocalProgramsPythonPython36python.exe
    Python Version: 3.6.5
    Python Path: ['F:git_codeemergency_itilEmergencyResponse', 'F:git_codeemergency_itilEmergencyResponse', 'E:PyCharm 2019.1.1helperspycharm_display', 'C:UsersWMAppDataLocalProgramsPythonPython36python36.zip', 'C:UsersWMAppDataLocalProgramsPythonPython36DLLs', 'C:UsersWMAppDataLocalProgramsPythonPython36lib', 'C:UsersWMAppDataLocalProgramsPythonPython36', 'C:UsersWMAppDataRoamingPythonPython36site-packages', 'C:UsersWMAppDataLocalProgramsPythonPython36libsite-packages', 'E:PyCharm 2019.1.1helperspycharm_matplotlib_backend']
    Server time: 星期一, 22 七月 2019 21:07:21 +0800

    异常原因:

    search_fields = ('content', 'detail','submitter')
    

    这是在view中模糊查询的字段,其中submitter字段是一个外键ForeignKey字段,而作为一个外键,它所对应的不是一个具体的字段,而是一个类。

    所以我们应该将其对应成为一个外键关联的摸一个具体的字段,如submitter__username

    search_fields = ('content', 'detail','submitter__username')
    
  • 相关阅读:
    代码是什么
    关于程序
    信息系统分析三原则
    设计的一个原则,妥协,不完美
    Algs4-1.4.30一个栈和一个steque实现的双向队列
    Algs4-1.4.31三个栈实现的双向队列
    Algs4-1.4.29两个栈实现的steque
    Algs4-1.4.27两个栈实现队列
    Algs4-1.4.28一个队列实现的栈
    *Algs4-1.4.26-三点共线-(未解决)
  • 原文地址:https://www.cnblogs.com/jiumo/p/11228460.html
Copyright © 2011-2022 走看看