django后台搜索报错:Related Field got invalid lookup: icontains

这个错误一般是由于你在admin.py文件里的search_fields使用了外键,而没有指定具体的字段。

比如:我的外键是author,写成:search_fields = (‘title’, ‘author’, )就会报错,儿应该写成:

search_fields = (‘title’, ‘author__name’, )

完整报错内容:

FieldError at /admin/app1/article/
Related Field got invalid lookup: icontains
Request Method:	GET
Request URL:	http://127.0.0.1:8000/admin/app1/article/?q=1
Django Version:	2.1.5
Exception Type:	FieldError
Exception Value:	
Related Field got invalid lookup: icontains
Exception Location:	C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\sql\query.py in build_lookup, line 1087
Python Executable:	C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python.exe
Python Version:	3.7.0
Python Path:	
['F:\\python\\untitled1',
 'F:\\python\\untitled1',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\python37.zip',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\DLLs',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\lib',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages',
 'D:\\Program Files\\JetBrains\\PyCharm '
 '2018.3.2\\helpers\\pycharm_matplotlib_backend']
Server time:	Wed, 16 Jan 2019 09:18:36 +0000
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值