事实上,这不是一个答案,而是对保罗的PR的评论。
使用保罗的代码且没有过滤器时,我收到了一个错误(Django 2.2.1):
ERROR Internal Server Error: /jet/model_lookup/
Traceback (most recent call last):
File "/home/mirek/dj/rian/ve_rian/lib/python3.7/site-packages/django/utils/datastructures.py", line 78, in __getitem__
list_ = super().__getitem__(key)
KeyError: 'filters'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/mirek/dj/rian/ve_rian/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/mirek/dj/rian/ve_rian/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/mirek/dj/rian/ve_rian/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/mirek/dj/rian/ve_rian/lib/python3.7/site-packages/django/views/decorators/http.py", line 40, in inner
return func(request, *args, **kwargs)
File "/home/mirek/dj/rian/isms/django-jet/jet/views.py", line 64, in model_lookup_view
items, total = form.lookup()
File "/home/mirek/dj/rian/isms/django-jet/jet/forms.py", line 135, in lookup
qs.query.__dict__ = pickle.loads(codecs.decode(self.data['filters'].encode(), 'base64'))
File "/home/mirek/dj/rian/ve_rian/lib/python3.7/site-packages/django/utils/datastructures.py", line 80, in __getitem__
raise MultiValueDictKeyError(key)
django.utils.datastructures.MultiValueDictKeyError: 'filters'
如果我在jet/forms.py中更改您的代码,这个错误就不会再出现了:
def lookup(self):
if 'filters' in self.data:
qs = self.model_cls.objects.all()
qs.query.__dict__ = pickle.loads(codecs.decode(self.data['filters'].encode(), 'base64'))
else:
qs = self.model_cls.objects
然而我不知道过滤器是否完全正常工作(因为我没有测试过,因为我不使用过滤器)。