diff --git a/django/contrib/admin/filterspecs.py b/django/contrib/admin/filterspecs.py
a
|
b
|
|
89 | 89 | yield {'selected': self.lookup_val is None, |
90 | 90 | 'query_string': cl.get_query_string({}, [self.lookup_kwarg]), |
91 | 91 | 'display': _('All')} |
92 | | for k, v in self.field.choices: |
| 92 | for k, v in self.field.flatchoices: |
93 | 93 | yield {'selected': smart_unicode(k) == self.lookup_val, |
94 | 94 | 'query_string': cl.get_query_string({self.lookup_kwarg: k}), |
95 | 95 | 'display': v} |
diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
a
|
b
|
|
134 | 134 | class ThingAdmin(admin.ModelAdmin): |
135 | 135 | list_filter = ('color',) |
136 | 136 | |
| 137 | class Fabric(models.Model): |
| 138 | NG_CHOICES = ( |
| 139 | ('Textured', ( |
| 140 | ('x', 'Horizontal'), |
| 141 | ('y', 'Vertical'), |
| 142 | ) |
| 143 | ), |
| 144 | ('plain', 'Smooth'), |
| 145 | ) |
| 146 | surface = models.CharField(max_length=20, choices=NG_CHOICES) |
| 147 | |
| 148 | class FabricAdmin(admin.ModelAdmin): |
| 149 | list_filter = ('surface',) |
| 150 | |
137 | 151 | admin.site.register(Article, ArticleAdmin) |
138 | 152 | admin.site.register(CustomArticle, CustomArticleAdmin) |
139 | 153 | admin.site.register(Section, inlines=[ArticleInline]) |
140 | 154 | admin.site.register(ModelWithStringPrimaryKey) |
141 | 155 | admin.site.register(Color) |
142 | 156 | admin.site.register(Thing, ThingAdmin) |
| 157 | admin.site.register(Fabric, FabricAdmin) |
143 | 158 | |
144 | 159 | # We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2. |
145 | 160 | # That way we cover all four cases: |
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
a
|
b
|
|
160 | 160 | '<a href="?color__id__exact=3">Blue</a>' in response.content, |
161 | 161 | "Changelist filter not correctly limited by limit_choices_to." |
162 | 162 | ) |
163 | | |
| 163 | |
| 164 | def testNamedGroupFieldChoicesFilter(self): |
| 165 | """ |
| 166 | Ensures the filter UI shows correctly when at least one named group has |
| 167 | been used in the choices option of a model field. |
| 168 | """ |
| 169 | response = self.client.get('/test_admin/admin/admin_views/fabric/') |
| 170 | self.failUnlessEqual(response.status_code, 200) |
| 171 | self.failUnless( |
| 172 | '<div id="changelist-filter">' in response.content, |
| 173 | "Expected filter not found in changelist view." |
| 174 | ) |
| 175 | self.failUnless( |
| 176 | '<a href="?surface__exact=x">Horizontal</a>' in response.content and |
| 177 | '<a href="?surface__exact=y">Vertical</a>' in response.content, |
| 178 | "Changelist filter isn't showing options contained inside a model field 'choices' option named group." |
| 179 | ) |
| 180 | |
164 | 181 | def testIncorrectLookupParameters(self): |
165 | 182 | """Ensure incorrect lookup parameters are handled gracefully.""" |
166 | 183 | response = self.client.get('/test_admin/admin/admin_views/thing/', {'notarealfield': '5'}) |