Code

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 marcob, 3 years ago)

A newer patch I apply after the #3400 one (don't know if works with trunk, give it a try)

Line 
1Index: django/contrib/admin/filterspecs.py
2===================================================================
3--- django\contrib\admin\filterspecs.py Tue Dec 28 21:37:31 2010
4+++ django\contrib\admin\filterspecs.orig       Tue Dec 28 19:40:28 2010
5@@ -76,9 +76,7 @@
6             self.lookup_title = f.verbose_name # use field name
7         rel_name = other_model._meta.pk.name
8         self.lookup_kwarg = '%s__%s__exact' % (self.field_path, rel_name)
9-        self.lookup_null_kwarg = '%s__isnull' % (self.field_path) #f.name
10         self.lookup_val = request.GET.get(self.lookup_kwarg, None)
11-        self.lookup_null = request.GET.get(self.lookup_null_kwarg, None)
12         self.lookup_choices = f.get_choices(include_blank=False)
13         
14     def has_output(self):
15@@ -88,17 +86,13 @@
16         return self.lookup_title
17 
18     def choices(self, cl):
19-        yield {'selected': self.lookup_val is None and not self.lookup_null,
20-               'query_string': cl.get_query_string({}, [self.lookup_kwarg, self.lookup_null_kwarg]),
21+        yield {'selected': self.lookup_val is None,
22+               'query_string': cl.get_query_string({}, [self.lookup_kwarg]),
23                'display': _('All')}
24         for pk_val, val in self.lookup_choices:
25             yield {'selected': self.lookup_val == smart_unicode(pk_val),
26-                   'query_string': cl.get_query_string({self.lookup_kwarg: pk_val}, [self.lookup_null_kwarg]),
27+                   'query_string': cl.get_query_string({self.lookup_kwarg: pk_val}),
28                    'display': val}
29-        if self.field.null:
30-            yield {'selected': self.lookup_null,
31-                   'query_string': cl.get_query_string({self.lookup_null_kwarg: 'True'}, [self.lookup_kwarg]),
32-                   'display': '(%s)' % _("None")}
33 
34 FilterSpec.register(lambda f: (
35         hasattr(f, 'rel') and bool(f.rel) or
36@@ -198,11 +192,8 @@
37         super(AllValuesFilterSpec, self).__init__(f, request, params, model,
38                                                   model_admin,
39                                                   field_path=field_path)
40-        self.lookup_kwarg = self.field_path
41-        self.lookup_kwarg_isnull = '%s__isnull' % self.field_path
42-        self.lookup_val = request.GET.get(self.lookup_kwarg, None)
43-        self.lookup_val_isnull = request.GET.get(self.lookup_kwarg_isnull, None)
44-        parent_model, reverse_path = reverse_field_path(model, self.field_path)
45+        self.lookup_val = request.GET.get(self.field_path, None)
46+        parent_model, reverse_path = reverse_field_path(model, field_path)
47         queryset = parent_model._default_manager.all()
48         # optional feature: limit choices base on existing relationships
49         # queryset = queryset.complex_filter(
50@@ -211,29 +202,18 @@
51         queryset = queryset.filter(limit_choices_to)
52         
53         self.lookup_choices = \
54-            queryset.distinct().order_by(f.name).values_list(f.name, flat=True)
55+            queryset.distinct().order_by(f.name).values(f.name)
56 
57     def title(self):
58         return self.field.verbose_name
59 
60     def choices(self, cl):
61-        yield {'selected': self.lookup_val is None and self.lookup_val_isnull is None,
62-               'query_string': cl.get_query_string({}, [self.lookup_kwarg, self.lookup_kwarg_isnull]),
63+        yield {'selected': self.lookup_val is None,
64+               'query_string': cl.get_query_string({}, [self.field_path]),
65                'display': _('All')}
66-        include_none = False
67-       
68         for val in self.lookup_choices:
69-            if val is None:
70-                include_none = True
71-                continue
72-            val = smart_unicode(val)
73-           
74+            val = smart_unicode(val[self.field.name])
75             yield {'selected': self.lookup_val == val,
76-                   'query_string': cl.get_query_string({self.lookup_kwarg: val}, [self.lookup_kwarg_isnull]),
77+                   'query_string': cl.get_query_string({self.field_path: val}),
78                    'display': val}
79-        if include_none:
80-            yield {'selected': self.lookup_val_isnull is not None,
81-                    'query_string': cl.get_query_string({self.lookup_kwarg_isnull: 'True'}, [self.lookup_kwarg]),
82-                    'display': _('None')}
83-
84 FilterSpec.register(lambda f: True, AllValuesFilterSpec)