Django Admin Custom Change List Arguments: Override /?e=1 Django Admin Custom Change List Arguments: Override /?e=1 django django

Django Admin Custom Change List Arguments: Override /?e=1


I think you just need to put your custom filter fields in the search_fields class variable as outlined in the Advanced Search Django Snippet.

You should be able to modify the snippet to support date ranges as well.


In summary, here is the undocumented hack used above:

set request.GET._mutable = True, then request.GET.pop() off the custom GET argument(s) you are using.


I know this is an old post, but just ran into a need for this and discovered a very short and simple solution that I thought I would share. Key here is to make a filter that doesn't affect the queryset and accepts anything passed to it in the lookups as valid option. Something like the following:

from django.contrib.admin import SimpleListFilter    class PassThroughFilter(SimpleListFilter):    title = ''    parameter_name = 'pt'    template = 'admin/hidden_filter.html'    def lookups(self, request, model_admin):        return (request.GET.get(self.parameter_name), ''),    def queryset(self, request, queryset):        return queryset

The hidden_filter template is blank to prevent adding anything to the filter area, and the lookups method will always return whatever I have entered for the pt parameter as a valid filter entry. This will prevent the ?e=1 error from popping up as the page loads.

This can be reused with any admin, using the pt parameter. If you need to pass multiple parameters for a single admin, then just subclass this into separate filters and override parameter_name with whatever parameters you need. This will have the effect of allowing those parameters in the query string without affecting the queryset or showing up in the filter column, and you can then use them for whatever purpose you needed them elsewhere.

Hope this helps someone down the road.