1👍
Django is too magical sometimes. There is almost certainly a right way to do this, and what I’m doing is probably not it. But I modified my init function to delete my special parameters from the dictionary; and thus the django admin ignored it.
def __init__(self, request, params, model, model_admin):
super(ListFilter, self).__init__()
for param_key in self.parameters:
if param_key in params.keys():
self.parameter_values[param_key] = params[param_key]
del params[param_key] # This is the anti-magic line
else:
self.parameter_values[param_key] = ''
self.lookup_choices = list(self.lookups())
-1👍
I’ve seen that happen indeed: it seems you need to leave a “clean” set of parameters to the view.
I’ve seen pop() is used as a more efficient alternative:
def __init__(self, request, params, model, model_admin):
super(ListFilter, self).__init__()
for param_key in self.parameters:
self.parameter_values[param_key] = params.pop(param_key,'')
self.lookup_choices = list(self.lookups())
👤lai
- [Django]-Why I am Getting '_SIGCHLDWaker' object has no attribute 'doWrite' in Scrapy?
- [Django]-Collectstatic command excluding nested directories and files
- [Django]-Manage.py doesn't pass the argument to the command
- [Django]-Django REST framework nested serializer and POST nested JSON with files
- [Django]-How to use ListSerializer with a ModelSerializer?
Source:stackexchange.com