diff -r a21ec5adcb71 tests/regressiontests/admin_views/fixtures/admin-views-fabrics.xml
-
|
+
|
|
| 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | <django-objects version="1.0"> |
| 3 | <object pk="1" model="admin_views.fabric"> |
| 4 | <field type="CharField" name="surface">x</field> |
| 5 | </object> |
| 6 | <object pk="2" model="admin_views.fabric"> |
| 7 | <field type="CharField" name="surface">y</field> |
| 8 | </object> |
| 9 | <object pk="3" model="admin_views.fabric"> |
| 10 | <field type="CharField" name="surface">plain</field> |
| 11 | </object> |
| 12 | </django-objects> |
diff -r a21ec5adcb71 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_display = ('surface',) |
| 150 | list_filter = ('surface',) |
| 151 | |
137 | 152 | admin.site.register(Article, ArticleAdmin) |
138 | 153 | admin.site.register(CustomArticle, CustomArticleAdmin) |
139 | 154 | admin.site.register(Section, inlines=[ArticleInline]) |
140 | 155 | admin.site.register(ModelWithStringPrimaryKey) |
141 | 156 | admin.site.register(Color) |
142 | 157 | admin.site.register(Thing, ThingAdmin) |
| 158 | admin.site.register(Fabric, FabricAdmin) |
143 | 159 | |
144 | 160 | # We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2. |
145 | 161 | # That way we cover all four cases: |
diff -r a21ec5adcb71 tests/regressiontests/admin_views/tests.py
a
|
b
|
|
12 | 12 | from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey |
13 | 13 | |
14 | 14 | class AdminViewBasicTest(TestCase): |
15 | | fixtures = ['admin-views-users.xml', 'admin-views-colors.xml'] |
16 | | |
| 15 | fixtures = ['admin-views-users.xml', 'admin-views-colors.xml', 'admin-views-fabrics.xml'] |
| 16 | |
17 | 17 | def setUp(self): |
18 | 18 | self.client.login(username='super', password='secret') |
19 | 19 | |
… |
… |
|
147 | 147 | response.content.index('Middle content') < response.content.index('Newest content'), |
148 | 148 | "Results of sorting on ModelAdmin method are out of order." |
149 | 149 | ) |
150 | | |
| 150 | |
| 151 | def testNamedGroupFieldChoicesChangeList(self): |
| 152 | """ |
| 153 | Ensures the admin changelist shows correct values in the relevant column |
| 154 | for rows corresponding to instances of a model in which a named group |
| 155 | has been used in the choices option of a field. |
| 156 | """ |
| 157 | response = self.client.get('/test_admin/admin/admin_views/fabric/') |
| 158 | self.failUnlessEqual(response.status_code, 200) |
| 159 | self.failUnless( |
| 160 | '<a href="1/">Horizontal</a>' in response.content and |
| 161 | '<a href="2/">Vertical</a>' in response.content, |
| 162 | "Changelist table isn't showing the right human-readable values set by a model field 'choices' option named group." |
| 163 | ) |
| 164 | |
151 | 165 | def testLimitedFilter(self): |
152 | 166 | """Ensure admin changelist filters do not contain objects excluded via limit_choices_to.""" |
153 | 167 | response = self.client.get('/test_admin/admin/admin_views/thing/') |