Created
June 1, 2011 08:59
-
-
Save lprsd/1002008 to your computer and use it in GitHub Desktop.
django admin default filter values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this maybe works better.
when following admin navigation, the filter will become effective.
when open the url directly, the filter will not work.
def changelist_view(self, request, extra_context=None):
ref = request.META.get('HTTP_REFERER', '').split('?')[0]
if ref and not ref.endswith(request.path):
...