Created
September 25, 2016 13:47
-
-
Save urodoz/5d2fb94bc8e9af74339bd756627afe9f to your computer and use it in GitHub Desktop.
Django Null/Not null admin filter
This file contains hidden or 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
from django.contrib.admin import SimpleListFilter | |
class NullListFilter(SimpleListFilter): | |
def lookups(self, request, model_admin): | |
return ( | |
('1', 'Null',), | |
('0', '!= Null',), | |
) | |
def queryset(self, request, queryset): | |
if self.value() in ('0', '1'): | |
kwargs = {'{0}__isnull'.format(self.parameter_name): self.value() == '1'} | |
return queryset.filter(**kwargs) | |
return queryset | |
class StartedNullListFilter(NullListFilter): | |
title = u'Started' | |
parameter_name = u'started' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment