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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
from django.utils.translation import ugettext_lazy as _
from django.contrib.admin import SimpleListFilter
import models
class HasParent(SimpleListFilter):
# Human-readable title which will be displayed in the
# right admin sidebar just above the filter options.
title = _('has parent')
# Parameter for the filter that will be used in the URL query.
parameter_name = 'has_parent'
def lookups(self, request, model_admin):
"""
Returns a list of tuples. The first element in each
tuple is the coded value for the option that will
appear in the URL query. The second element is the
human-readable name for the option that will appear
in the right sidebar.
"""
return (
('yes', _('Yes')),
('no', _('No')),
)
def queryset(self, request, queryset):
"""
Returns the filtered queryset based on the value
provided in the query string and retrievable via
`self.value()`.
"""
# Compare the requested value (either 'None' or 'other')
# to decide how to filter the queryset.
if self.value() == 'yes':
return queryset.filter(parent__isnull = False)
if self.value() == 'no':
return queryset.filter(parent__isnull = True)
class HasBarcode(SimpleListFilter):
# Human-readable title which will be displayed in the
# right admin sidebar just above the filter options.
title = _('has barcode')
# Parameter for the filter that will be used in the URL query.
parameter_name = 'has_barcode'
def lookups(self, request, model_admin):
"""
Returns a list of tuples. The first element in each
tuple is the coded value for the option that will
appear in the URL query. The second element is the
human-readable name for the option that will appear
in the right sidebar.
"""
return (
('yes', _('Yes')),
('no', _('No')),
)
def queryset(self, request, queryset):
"""
Returns the filtered queryset based on the value
provided in the query string and retrievable via
`self.value()`.
"""
# Compare the requested value (either 'None' or 'other')
# to decide how to filter the queryset.
if self.value() == 'yes':
return queryset.filter(barcode__isnull = False)
if self.value() == 'no':
return queryset.filter(barcode__isnull = True)
class HasIcon(SimpleListFilter):
# Human-readable title which will be displayed in the
# right admin sidebar just above the filter options.
title = _('has icon')
# Parameter for the filter that will be used in the URL query.
parameter_name = 'has_icon'
def lookups(self, request, model_admin):
"""
Returns a list of tuples. The first element in each
tuple is the coded value for the option that will
appear in the URL query. The second element is the
human-readable name for the option that will appear
in the right sidebar.
"""
return (
('yes', _('Yes')),
('no', _('No')),
)
def queryset(self, request, queryset):
"""
Returns the filtered queryset based on the value
provided in the query string and retrievable via
`self.value()`.
"""
# Compare the requested value (either 'None' or 'other')
# to decide how to filter the queryset.
if self.value() == 'yes':
return queryset.filter(icon__isnull = False)
if self.value() == 'no':
return queryset.filter(icon__isnull = True)
|