13-3 relfield_style 报错 lookup失败
来源:13-3 model_icon, 只读字段,默认排序设置
慕粉dragon
2017-04-21
class Course(models.Model): course_org = models.ForeignKey(CourseOrg,verbose_name=u'课程机构',null=True,blank=True) name = models.CharField(max_length=50,verbose_name=u'课程名') desc = models.CharField(max_length=300,verbose_name=u'课程描述') detail = models.TextField(verbose_name=u'课程详情')
class CourseAdmin(object): list_display = ['name', 'desc', 'detail', 'degree','learn_times','students','fav_nums','image','click_nums','add_time'] search_fields = ['name', 'desc', 'detail', 'degree','students','fav_nums','image','click_nums'] list_filter = ['name', 'desc', 'detail', 'degree','learn_times','students','fav_nums','image','click_nums','add_time'] ordering = ['-click_nums']
Internal Server Error: /xadmin/organization/courseorg/ Traceback (most recent call last): File "C:\Users\thinkpad\Envs\mxonline\lib\site-packages\django-1.9.12-py2.7.egg\django\core\handlers\base.py", line 149, in get_response response = self.process_exception_by_middleware(e, request) File "C:\Users\thinkpad\Envs\mxonline\lib\site-packages\django-1.9.12-py2.7.egg\django\core\handlers\base.py", line 147, in get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "E:\PycharmProjects\MxOnline\extra_apps\xadmin\sites.py", line 296, in wrapper return self.admin_view(view, cacheable)(*args, **kwargs) File "C:\Users\thinkpad\Envs\mxonline\lib\site-packages\django-1.9.12-py2.7.egg\django\views\decorators\cache.py", line 57, in _wrapped_view_func response = view_func(request, *args, **kwargs) File "E:\PycharmProjects\MxOnline\extra_apps\xadmin\sites.py", line 204, in inner return view(request, *args, **kwargs) File "E:\PycharmProjects\MxOnline\extra_apps\xadmin\views\base.py", line 274, in view return handler(request, *args, **kwargs) File "C:\Users\thinkpad\Envs\mxonline\lib\site-packages\django-1.9.12-py2.7.egg\django\utils\decorators.py", line 67, in _wrapper return bound_func(*args, **kwargs) File "C:\Users\thinkpad\Envs\mxonline\lib\site-packages\django-1.9.12-py2.7.egg\django\utils\decorators.py", line 149, in _wrapped_view response = view_func(request, *args, **kwargs) File "C:\Users\thinkpad\Envs\mxonline\lib\site-packages\django-1.9.12-py2.7.egg\django\utils\decorators.py", line 63, in bound_func return func.__get__(self, type(self))(*args2, **kwargs2) File "E:\PycharmProjects\MxOnline\extra_apps\xadmin\views\base.py", line 78, in method return filter_chain(filters, len(filters) - 1, _inner_method, *args, **kwargs) File "E:\PycharmProjects\MxOnline\extra_apps\xadmin\views\base.py", line 47, in filter_chain return func() File "E:\PycharmProjects\MxOnline\extra_apps\xadmin\views\base.py", line 72, in _inner_method return func(self, *args, **kwargs) File "E:\PycharmProjects\MxOnline\extra_apps\xadmin\views\list.py", line 405, in get response = self.get_result_list() File "E:\PycharmProjects\MxOnline\extra_apps\xadmin\views\base.py", line 78, in method return filter_chain(filters, len(filters) - 1, _inner_method, *args, **kwargs) File "E:\PycharmProjects\MxOnline\extra_apps\xadmin\views\base.py", line 61, in filter_chain return filter_chain(filters, token - 1, _inner_method, *args, **kwargs) File "E:\PycharmProjects\MxOnline\extra_apps\xadmin\views\base.py", line 47, in filter_chain return func() File "E:\PycharmProjects\MxOnline\extra_apps\xadmin\views\base.py", line 60, in _inner_method return fm(func if fargs[1] == '__' else func(), *args, **kwargs) File "E:\PycharmProjects\MxOnline\extra_apps\xadmin\views\base.py", line 72, in _inner_method return func(self, *args, **kwargs) File "E:\PycharmProjects\MxOnline\extra_apps\xadmin\views\list.py", line 207, in get_result_list return self.make_result_list() File "E:\PycharmProjects\MxOnline\extra_apps\xadmin\views\list.py", line 170, in make_result_list self.list_queryset = self.get_list_queryset() File "E:\PycharmProjects\MxOnline\extra_apps\xadmin\views\base.py", line 78, in method return filter_chain(filters, len(filters) - 1, _inner_method, *args, **kwargs) File "E:\PycharmProjects\MxOnline\extra_apps\xadmin\views\base.py", line 61, in filter_chain return filter_chain(filters, token - 1, _inner_method, *args, **kwargs) File "E:\PycharmProjects\MxOnline\extra_apps\xadmin\views\base.py", line 47, in filter_chain return func() File "E:\PycharmProjects\MxOnline\extra_apps\xadmin\views\base.py", line 60, in _inner_method return fm(func if fargs[1] == '__' else func(), *args, **kwargs) File "E:\PycharmProjects\MxOnline\extra_apps\xadmin\plugins\filters.py", line 177, in get_list_queryset queryset = queryset.filter(reduce(operator.or_, or_queries)) File "C:\Users\thinkpad\Envs\mxonline\lib\site-packages\django-1.9.12-py2.7.egg\django\db\models\query.py", line 790, in filter return self._filter_or_exclude(False, *args, **kwargs) File "C:\Users\thinkpad\Envs\mxonline\lib\site-packages\django-1.9.12-py2.7.egg\django\db\models\query.py", line 808, in _filter_or_exclude clone.query.add_q(Q(*args, **kwargs)) File "C:\Users\thinkpad\Envs\mxonline\lib\site-packages\django-1.9.12-py2.7.egg\django\db\models\sql\query.py", line 1243, in add_q clause, _ = self._add_q(q_object, self.used_aliases) File "C:\Users\thinkpad\Envs\mxonline\lib\site-packages\django-1.9.12-py2.7.egg\django\db\models\sql\query.py", line 1263, in _add_q current_negated, allow_joins, split_subq) File "C:\Users\thinkpad\Envs\mxonline\lib\site-packages\django-1.9.12-py2.7.egg\django\db\models\sql\query.py", line 1269, in _add_q allow_joins=allow_joins, split_subq=split_subq, File "C:\Users\thinkpad\Envs\mxonline\lib\site-packages\django-1.9.12-py2.7.egg\django\db\models\sql\query.py", line 1194, in build_filter lookup_class = field.get_lookup(lookups[0]) File "C:\Users\thinkpad\Envs\mxonline\lib\site-packages\django-1.9.12-py2.7.egg\django\db\models\fields\related.py", line 693, in get_lookup raise TypeError('Related Field got invalid lookup: %s' % lookup_name) TypeError: Related Field got invalid lookup: icontains [21/Apr/2017 17:28:06] "GET /xadmin/organization/courseorg/?&_q_=%E6%85%95%E8%AF%BE%E7%BD%91&_cols=id.__str__ HTTP/1.1" 500 22505
写回答
1回答
-
TypeError: Related Field got invalid lookup: icontains 这个错误一般都是因为你搜索了外键的字段了 你看看你有没有什么地方指名了外键的字段 或者给我发一个qq消息我给你看看
032017-07-13
相似问题