-
Notifications
You must be signed in to change notification settings - Fork 705
/
admin_filters.py
31 lines (26 loc) · 1.12 KB
/
admin_filters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from django.utils.translation import ugettext_lazy as _
from django.contrib.admin import FieldListFilter
class IsNullFieldListFilter(FieldListFilter):
notnull_label = _('Is present')
isnull_label = _('Is Null')
def __init__(self, field, request, params, model, model_admin, field_path):
self.lookup_kwarg = '%s__isnull' % field_path
self.lookup_val = request.GET.get(self.lookup_kwarg, None)
super(IsNullFieldListFilter, self).__init__(field,
request, params, model,
model_admin, field_path)
def expected_parameters(self):
return [self.lookup_kwarg]
def choices(self, cl):
for lookup, title in (
(None, _('All')),
('False', self.notnull_label),
('True', self.isnull_label),
):
yield {
'selected': self.lookup_val == lookup,
'query_string': cl.get_query_string({
self.lookup_kwarg: lookup,
}),
'display': title,
}