Ticket #5273: 5273.patch
File 5273.patch, 2.3 KB (added by , 17 years ago) |
---|
-
D:/web/projects/django-newforms/django/contrib/admin/filterspecs.py
59 59 self.lookup_kwarg = '%s__%s__exact' % (f.name, f.rel.to._meta.pk.name) 60 60 self.lookup_val = request.GET.get(self.lookup_kwarg, None) 61 61 self.lookup_choices = f.rel.to._default_manager.all() 62 #lookup_none_kwarg defined only on nullable fields, empty string otherwise 63 self.lookup_none_kwarg = (f.null or '') and '%s__%s__isnull' % (f.name, f.rel.to._meta.pk.name) 64 self.lookup_none_val = request.GET.get(self.lookup_none_kwarg, None) 62 65 63 66 def has_output(self): 64 67 return len(self.lookup_choices) > 1 … … 67 70 return self.lookup_title 68 71 69 72 def choices(self, cl): 70 yield {'selected': self.lookup_val is None, 71 'query_string': cl.get_query_string({}, [self.lookup_kwarg]), 73 yield {'selected': self.lookup_val is None and self.lookup_none_val is None, 74 'query_string': cl.get_query_string({}, [self.lookup_kwarg, 75 self.lookup_none_kwarg]), 72 76 'display': _('All')} 73 77 for val in self.lookup_choices: 74 78 pk_val = getattr(val, self.field.rel.to._meta.pk.attname) … … 73 77 for val in self.lookup_choices: 74 78 pk_val = getattr(val, self.field.rel.to._meta.pk.attname) 75 79 yield {'selected': self.lookup_val == smart_unicode(pk_val), 76 'query_string': cl.get_query_string({self.lookup_kwarg: pk_val}), 80 'query_string': cl.get_query_string({self.lookup_kwarg: pk_val}, 81 [self.lookup_none_kwarg]), 77 82 'display': val} 83 if self.lookup_none_kwarg: 84 yield {'selected': self.lookup_none_val != None, 85 'query_string': cl.get_query_string({self.lookup_none_kwarg: True}, 86 [self.lookup_kwarg]), 87 'display': _('None')} 78 88 79 89 FilterSpec.register(lambda f: bool(f.rel), RelatedFilterSpec)