Ticket #8528: ticket8528-1.2.4.after.3400.1.2.4.diff
File ticket8528-1.2.4.after.3400.1.2.4.diff, 4.3 KB (added by , 14 years ago) |
---|
-
django\contrib\admin\filterspecs.
old new 76 76 self.lookup_title = f.verbose_name # use field name 77 77 rel_name = other_model._meta.pk.name 78 78 self.lookup_kwarg = '%s__%s__exact' % (self.field_path, rel_name) 79 self.lookup_null_kwarg = '%s__isnull' % (self.field_path) #f.name80 79 self.lookup_val = request.GET.get(self.lookup_kwarg, None) 81 self.lookup_null = request.GET.get(self.lookup_null_kwarg, None)82 80 self.lookup_choices = f.get_choices(include_blank=False) 83 81 84 82 def has_output(self): … … 88 86 return self.lookup_title 89 87 90 88 def choices(self, cl): 91 yield {'selected': self.lookup_val is None and not self.lookup_null,92 'query_string': cl.get_query_string({}, [self.lookup_kwarg , self.lookup_null_kwarg]),89 yield {'selected': self.lookup_val is None, 90 'query_string': cl.get_query_string({}, [self.lookup_kwarg]), 93 91 'display': _('All')} 94 92 for pk_val, val in self.lookup_choices: 95 93 yield {'selected': self.lookup_val == smart_unicode(pk_val), 96 'query_string': cl.get_query_string({self.lookup_kwarg: pk_val} , [self.lookup_null_kwarg]),94 'query_string': cl.get_query_string({self.lookup_kwarg: pk_val}), 97 95 'display': val} 98 if self.field.null:99 yield {'selected': self.lookup_null,100 'query_string': cl.get_query_string({self.lookup_null_kwarg: 'True'}, [self.lookup_kwarg]),101 'display': '(%s)' % _("None")}102 96 103 97 FilterSpec.register(lambda f: ( 104 98 hasattr(f, 'rel') and bool(f.rel) or … … 198 192 super(AllValuesFilterSpec, self).__init__(f, request, params, model, 199 193 model_admin, 200 194 field_path=field_path) 201 self.lookup_kwarg = self.field_path 202 self.lookup_kwarg_isnull = '%s__isnull' % self.field_path 203 self.lookup_val = request.GET.get(self.lookup_kwarg, None) 204 self.lookup_val_isnull = request.GET.get(self.lookup_kwarg_isnull, None) 205 parent_model, reverse_path = reverse_field_path(model, self.field_path) 195 self.lookup_val = request.GET.get(self.field_path, None) 196 parent_model, reverse_path = reverse_field_path(model, field_path) 206 197 queryset = parent_model._default_manager.all() 207 198 # optional feature: limit choices base on existing relationships 208 199 # queryset = queryset.complex_filter( … … 211 202 queryset = queryset.filter(limit_choices_to) 212 203 213 204 self.lookup_choices = \ 214 queryset.distinct().order_by(f.name).values _list(f.name, flat=True)205 queryset.distinct().order_by(f.name).values(f.name) 215 206 216 207 def title(self): 217 208 return self.field.verbose_name 218 209 219 210 def choices(self, cl): 220 yield {'selected': self.lookup_val is None and self.lookup_val_isnull is None,221 'query_string': cl.get_query_string({}, [self. lookup_kwarg, self.lookup_kwarg_isnull]),211 yield {'selected': self.lookup_val is None, 212 'query_string': cl.get_query_string({}, [self.field_path]), 222 213 'display': _('All')} 223 include_none = False224 225 214 for val in self.lookup_choices: 226 if val is None: 227 include_none = True 228 continue 229 val = smart_unicode(val) 230 215 val = smart_unicode(val[self.field.name]) 231 216 yield {'selected': self.lookup_val == val, 232 'query_string': cl.get_query_string({self. lookup_kwarg: val}, [self.lookup_kwarg_isnull]),217 'query_string': cl.get_query_string({self.field_path: val}), 233 218 'display': val} 234 if include_none:235 yield {'selected': self.lookup_val_isnull is not None,236 'query_string': cl.get_query_string({self.lookup_kwarg_isnull: 'True'}, [self.lookup_kwarg]),237 'display': _('None')}238 239 219 FilterSpec.register(lambda f: True, AllValuesFilterSpec)