Created
August 12, 2018 07:11
-
-
Save nonamenix/1882493d21fc3d214e43bcdde58256e4 to your computer and use it in GitHub Desktop.
NullFilter for django admin
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
from django.contrib.admin import SimpleListFilter | |
from django.utils.translation import gettext_lazy as _ | |
class NullFilter(SimpleListFilter): | |
title = '' | |
parameter_name = '' | |
def lookups(self, request, model_admin): | |
return ( | |
('0', _('None'),), | |
) | |
def queryset(self, request, queryset): | |
kwargs = { | |
'%s' % self.parameter_name: None, | |
} | |
if self.value() == '0': | |
return queryset.filter(**kwargs) | |
if self.value() == '1': | |
return queryset.exclude(**kwargs) | |
return queryset | |
class PriceNullFilter(NullFilter): | |
title = _('Price') | |
parameter_name = 'price' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment