Ticket #14467: AllValuesFilterSpec_Null.diff
File AllValuesFilterSpec_Null.diff, 2.0 KB (added by , 14 years ago) |
---|
-
django/contrib/admin/filterspecs.py
161 161 class AllValuesFilterSpec(FilterSpec): 162 162 def __init__(self, f, request, params, model, model_admin): 163 163 super(AllValuesFilterSpec, self).__init__(f, request, params, model, model_admin) 164 self.lookup_val = request.GET.get(f.name, None) 164 self.lookup_kwarg = f.name 165 self.lookup_kwarg2 = '%s__isnull' % f.name 166 self.lookup_val = request.GET.get(self.lookup_kwarg, None) 167 self.lookup_val2 = request.GET.get(self.lookup_kwarg2, None) 165 168 self.lookup_choices = model_admin.queryset(request).distinct().order_by(f.name).values(f.name) 166 169 167 170 def title(self): 168 171 return self.field.verbose_name 169 172 170 173 def choices(self, cl): 171 yield {'selected': self.lookup_val is None ,172 'query_string': cl.get_query_string({}, [self. field.name]),174 yield {'selected': self.lookup_val is None and self.lookup_val2 is None, 175 'query_string': cl.get_query_string({}, [self.lookup_kwarg, self.lookup_kwarg2]), 173 176 'display': _('All')} 174 177 for val in self.lookup_choices: 175 val = smart_unicode(val[self.field.name]) 176 yield {'selected': self.lookup_val == val, 177 'query_string': cl.get_query_string({self.field.name: val}), 178 'display': val} 178 val = val[self.field.name] 179 if val is None: 180 val = smart_unicode(val) 181 yield {'selected': self.lookup_val2 is not None, 182 'query_string': cl.get_query_string({self.lookup_kwarg2: 'True'}, [self.lookup_kwarg]), 183 'display': val} 184 else: 185 val = smart_unicode(val) 186 yield {'selected': self.lookup_val2 == val, 187 'query_string': cl.get_query_string({self.lookup_kwarg: val}, [self.lookup_kwarg2]), 188 'display': val} 179 189 FilterSpec.register(lambda f: True, AllValuesFilterSpec)