django admin default filter values
class YourAdmin(ModelAdmin): | |
def changelist_view(self, request, extra_context=None): | |
ref = request.META.get('HTTP_REFERER','') | |
path = request.META.get('PATH_INFO','') | |
if not ref.split(path)[-1].startswith('?'): | |
q = request.GET.copy() | |
q['usertype'] = 'Publisher' | |
q['user_status__exact'] = 'activated' | |
request.GET = q | |
request.META['QUERY_STRING'] = request.GET.urlencode() | |
return super(BulkMigrationAdmin,self).changelist_view(request, extra_context=extra_context) |
This comment has been minimized.
This comment has been minimized.
This doesn't work. request.META.get('HTTP_REFERER', '') is page view behind. So the first time you try to change the filter value, you get the defaults again. |
This comment has been minimized.
This comment has been minimized.
this maybe works better. def changelist_view(self, request, extra_context=None): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
I changed it slightly, so as not to hardcode in the parameters, and instead pass them in in the admin view: