在xadmin后台添加课程页面要关联org,默认是下拉框,视频13-3里面有个地方讲可以把下拉框修改为通过ajax方式展示,
我具体方式如下:
class CourseOrgAdmin(object):
list_display = ['name', 'desc','click_nums','fav_nums','image','address','city','add_time']
search_fields = ['name', 'desc','click_nums','fav_nums','image','address','city']
list_filter = ['name', 'desc','click_nums','fav_nums','image','address','city','add_time']
relfield_style = 'fk-ajax' #以ajax方式加载外键
但是在输入框搜索的报错如下:
Starting development server at http://0.0.0.0:9999/
Quit the server with CONTROL-C.
Internal Server Error: /xadmin/organization/courseorg/
Traceback (most recent call last):
File "/Users/shine_forever/.virtualenvs/MXonline/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/shine_forever/.virtualenvs/MXonline/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/shine_forever/local_coding/MXonline/extra_apps/xadmin/sites.py", line 296, in wrapper
return self.admin_view(view, cacheable)(*args, **kwargs)
File "/Users/shine_forever/.virtualenvs/MXonline/lib/python2.7/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/Users/shine_forever/local_coding/MXonline/extra_apps/xadmin/sites.py", line 204, in inner
return view(request, *args, **kwargs)
File "/Users/shine_forever/local_coding/MXonline/extra_apps/xadmin/views/base.py", line 274, in view
return handler(request, *args, **kwargs)
File "/Users/shine_forever/.virtualenvs/MXonline/lib/python2.7/site-packages/django/utils/decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "/Users/shine_forever/.virtualenvs/MXonline/lib/python2.7/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Users/shine_forever/.virtualenvs/MXonline/lib/python2.7/site-packages/django/utils/decorators.py", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/Users/shine_forever/local_coding/MXonline/extra_apps/xadmin/views/base.py", line 78, in method
return filter_chain(filters, len(filters) - 1, _inner_method, *args, **kwargs)
File "/Users/shine_forever/local_coding/MXonline/extra_apps/xadmin/views/base.py", line 47, in filter_chain
return func()
File "/Users/shine_forever/local_coding/MXonline/extra_apps/xadmin/views/base.py", line 72, in _inner_method
return func(self, *args, **kwargs)
File "/Users/shine_forever/local_coding/MXonline/extra_apps/xadmin/views/list.py", line 405, in get
response = self.get_result_list()
File "/Users/shine_forever/local_coding/MXonline/extra_apps/xadmin/views/base.py", line 78, in method
return filter_chain(filters, len(filters) - 1, _inner_method, *args, **kwargs)
File "/Users/shine_forever/local_coding/MXonline/extra_apps/xadmin/views/base.py", line 61, in filter_chain
return filter_chain(filters, token - 1, _inner_method, *args, **kwargs)
File "/Users/shine_forever/local_coding/MXonline/extra_apps/xadmin/views/base.py", line 47, in filter_chain
return func()
File "/Users/shine_forever/local_coding/MXonline/extra_apps/xadmin/views/base.py", line 60, in _inner_method
return fm(func if fargs[1] == '__' else func(), *args, **kwargs)
File "/Users/shine_forever/local_coding/MXonline/extra_apps/xadmin/views/base.py", line 72, in _inner_method
return func(self, *args, **kwargs)
File "/Users/shine_forever/local_coding/MXonline/extra_apps/xadmin/views/list.py", line 207, in get_result_list
return self.make_result_list()
File "/Users/shine_forever/local_coding/MXonline/extra_apps/xadmin/views/list.py", line 170, in make_result_list
self.list_queryset = self.get_list_queryset()
File "/Users/shine_forever/local_coding/MXonline/extra_apps/xadmin/views/base.py", line 78, in method
return filter_chain(filters, len(filters) - 1, _inner_method, *args, **kwargs)
File "/Users/shine_forever/local_coding/MXonline/extra_apps/xadmin/views/base.py", line 61, in filter_chain
return filter_chain(filters, token - 1, _inner_method, *args, **kwargs)
File "/Users/shine_forever/local_coding/MXonline/extra_apps/xadmin/views/base.py", line 47, in filter_chain
return func()
File "/Users/shine_forever/local_coding/MXonline/extra_apps/xadmin/views/base.py", line 60, in _inner_method
return fm(func if fargs[1] == '__' else func(), *args, **kwargs)
File "/Users/shine_forever/local_coding/MXonline/extra_apps/xadmin/plugins/filters.py", line 177, in get_list_queryset
queryset = queryset.filter(reduce(operator.or_, or_queries))
File "/Users/shine_forever/.virtualenvs/MXonline/lib/python2.7/site-packages/django/db/models/query.py", line 790, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/Users/shine_forever/.virtualenvs/MXonline/lib/python2.7/site-packages/django/db/models/query.py", line 808, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/Users/shine_forever/.virtualenvs/MXonline/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1243, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "/Users/shine_forever/.virtualenvs/MXonline/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1263, in _add_q
current_negated, allow_joins, split_subq)
File "/Users/shine_forever/.virtualenvs/MXonline/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1269, in _add_q
allow_joins=allow_joins, split_subq=split_subq,
File "/Users/shine_forever/.virtualenvs/MXonline/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1194, in build_filter
lookup_class = field.get_lookup(lookups[0])
File "/Users/shine_forever/.virtualenvs/MXonline/lib/python2.7/site-packages/django/db/models/fields/related.py", line 688, in get_lookup
raise TypeError('Related Field got invalid lookup: %s' % lookup_name)
TypeError: Related Field got invalid lookup: icontains
[26/Apr/2017 11:14:42] "GET /xadmin/organization/courseorg/?&_q_=jig&_cols=id.__str__ HTTP/1.1" 500 20854