diff --git a/django/contrib/admin/filterspecs.py b/django/contrib/admin/filterspecs.py
index 1ca10ed..e15c758 100644
a
|
b
|
class FilterSpec(object):
|
19 | 19 | self.field_path = field_path or f.name |
20 | 20 | |
21 | 21 | def register(cls, test, factory): |
22 | | cls.filter_specs.append((test, factory)) |
| 22 | cls.filter_specs.insert(0, (test, factory)) |
23 | 23 | register = classmethod(register) |
24 | 24 | |
25 | 25 | def create(cls, f, request, params, model, model_admin, field_path=None): |
… |
… |
class RelatedFilterSpec(FilterSpec):
|
77 | 77 | 'query_string': cl.get_query_string({self.lookup_kwarg: pk_val}), |
78 | 78 | 'display': val} |
79 | 79 | |
80 | | FilterSpec.register(lambda f: bool(f.rel), RelatedFilterSpec) |
81 | | |
82 | 80 | class ChoicesFilterSpec(FilterSpec): |
83 | 81 | def __init__(self, f, request, params, model, model_admin, field_path=None): |
84 | 82 | super(ChoicesFilterSpec, self).__init__(f, request, params, model, model_admin, field_path=field_path) |
… |
… |
class ChoicesFilterSpec(FilterSpec):
|
94 | 92 | 'query_string': cl.get_query_string({self.lookup_kwarg: k}), |
95 | 93 | 'display': v} |
96 | 94 | |
97 | | FilterSpec.register(lambda f: bool(f.choices), ChoicesFilterSpec) |
98 | | |
99 | 95 | class DateFieldFilterSpec(FilterSpec): |
100 | 96 | def __init__(self, f, request, params, model, model_admin, field_path=None): |
101 | 97 | super(DateFieldFilterSpec, self).__init__(f, request, params, model, model_admin, field_path=field_path) |
… |
… |
class DateFieldFilterSpec(FilterSpec):
|
129 | 125 | 'query_string': cl.get_query_string(param_dict, [self.field_generic]), |
130 | 126 | 'display': title} |
131 | 127 | |
132 | | FilterSpec.register(lambda f: isinstance(f, models.DateField), DateFieldFilterSpec) |
133 | | |
134 | 128 | class BooleanFieldFilterSpec(FilterSpec): |
135 | 129 | def __init__(self, f, request, params, model, model_admin, field_path=None): |
136 | 130 | super(BooleanFieldFilterSpec, self).__init__(f, request, params, model, model_admin, field_path=field_path) |
… |
… |
class BooleanFieldFilterSpec(FilterSpec):
|
152 | 146 | 'query_string': cl.get_query_string({self.lookup_kwarg2: 'True'}, [self.lookup_kwarg]), |
153 | 147 | 'display': _('Unknown')} |
154 | 148 | |
155 | | FilterSpec.register(lambda f: isinstance(f, models.BooleanField) or isinstance(f, models.NullBooleanField), BooleanFieldFilterSpec) |
156 | | |
157 | | # This should be registered last, because it's a last resort. For example, |
158 | | # if a field is eligible to use the BooleanFieldFilterSpec, that'd be much |
159 | | # more appropriate, and the AllValuesFilterSpec won't get used for it. |
160 | 149 | class AllValuesFilterSpec(FilterSpec): |
161 | 150 | def __init__(self, f, request, params, model, model_admin, field_path=None): |
162 | 151 | super(AllValuesFilterSpec, self).__init__(f, request, params, model, model_admin, field_path=field_path) |
… |
… |
class AllValuesFilterSpec(FilterSpec):
|
176 | 165 | yield {'selected': self.lookup_val == val, |
177 | 166 | 'query_string': cl.get_query_string({self.field_path: val}), |
178 | 167 | 'display': val} |
| 168 | |
| 169 | # This should be registered first, because it's a last resort. For example, |
| 170 | # if a field is eligible to use the BooleanFieldFilterSpec, that'd be much |
| 171 | # more appropriate, and the AllValuesFilterSpec won't get used for it. |
179 | 172 | FilterSpec.register(lambda f: True, AllValuesFilterSpec) |
| 173 | FilterSpec.register(lambda f: isinstance(f, models.BooleanField) or isinstance(f, models.NullBooleanField), BooleanFieldFilterSpec) |
| 174 | FilterSpec.register(lambda f: isinstance(f, models.DateField), DateFieldFilterSpec) |
| 175 | FilterSpec.register(lambda f: bool(f.choices), ChoicesFilterSpec) |
| 176 | FilterSpec.register(lambda f: bool(f.rel), RelatedFilterSpec) |