diff options
| author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2009-04-01 21:17:54 +0000 |
|---|---|---|
| committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2009-04-01 21:17:54 +0000 |
| commit | eb24c7fd0c92559cef37f72bce44ca1157a6c3a9 (patch) | |
| tree | 51fa712f468092ff8b57aceabc310e9952a4ca83 /tests | |
| parent | d0dce0257b79cbea80098b4c043a9a5ec36d8b89 (diff) | |
[1.0.X] Fixed #9969: choices with options groups (added in [7977]) now work correctly in the admin with list_display and list_filter. Thanks, ramiro. Backport of r10318 from trunk; thanks, cramm.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10340 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/admin_views/fixtures/admin-views-fabrics.xml | 12 | ||||
| -rw-r--r-- | tests/regressiontests/admin_views/models.py | 16 | ||||
| -rw-r--r-- | tests/regressiontests/admin_views/tests.py | 33 |
3 files changed, 60 insertions, 1 deletions
diff --git a/tests/regressiontests/admin_views/fixtures/admin-views-fabrics.xml b/tests/regressiontests/admin_views/fixtures/admin-views-fabrics.xml new file mode 100644 index 0000000000..485bb27c2a --- /dev/null +++ b/tests/regressiontests/admin_views/fixtures/admin-views-fabrics.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<django-objects version="1.0"> + <object pk="1" model="admin_views.fabric"> + <field type="CharField" name="surface">x</field> + </object> + <object pk="2" model="admin_views.fabric"> + <field type="CharField" name="surface">y</field> + </object> + <object pk="3" model="admin_views.fabric"> + <field type="CharField" name="surface">plain</field> + </object> +</django-objects> diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py index fbfe59f97e..d9ac372da0 100644 --- a/tests/regressiontests/admin_views/models.py +++ b/tests/regressiontests/admin_views/models.py @@ -134,6 +134,21 @@ class Thing(models.Model): class ThingAdmin(admin.ModelAdmin): list_filter = ('color',) +class Fabric(models.Model): + NG_CHOICES = ( + ('Textured', ( + ('x', 'Horizontal'), + ('y', 'Vertical'), + ) + ), + ('plain', 'Smooth'), + ) + surface = models.CharField(max_length=20, choices=NG_CHOICES) + +class FabricAdmin(admin.ModelAdmin): + list_display = ('surface',) + list_filter = ('surface',) + class Persona(models.Model): """ A simple persona associated with accounts, to test inlining of related @@ -208,6 +223,7 @@ admin.site.register(Thing, ThingAdmin) admin.site.register(Persona, PersonaAdmin) admin.site.register(Parent, ParentAdmin) admin.site.register(EmptyModel, EmptyModelAdmin) +admin.site.register(Fabric, FabricAdmin) # We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2. # That way we cover all four cases: diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index 4db15fc14c..e1a23da37e 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -19,7 +19,7 @@ except NameError: from sets import Set as set class AdminViewBasicTest(TestCase): - fixtures = ['admin-views-users.xml', 'admin-views-colors.xml'] + fixtures = ['admin-views-users.xml', 'admin-views-colors.xml', 'admin-views-fabrics.xml'] def setUp(self): self.client.login(username='super', password='secret') @@ -175,6 +175,37 @@ class AdminViewBasicTest(TestCase): response = self.client.get('/test_admin/admin/admin_views/thing/', {'color__id__exact': 'StringNotInteger!'}) self.assertRedirects(response, '/test_admin/admin/admin_views/thing/?e=1') + def testNamedGroupFieldChoicesChangeList(self): + """ + Ensures the admin changelist shows correct values in the relevant column + for rows corresponding to instances of a model in which a named group + has been used in the choices option of a field. + """ + response = self.client.get('/test_admin/admin/admin_views/fabric/') + self.failUnlessEqual(response.status_code, 200) + self.failUnless( + '<a href="1/">Horizontal</a>' in response.content and + '<a href="2/">Vertical</a>' in response.content, + "Changelist table isn't showing the right human-readable values set by a model field 'choices' option named group." + ) + + def testNamedGroupFieldChoicesFilter(self): + """ + Ensures the filter UI shows correctly when at least one named group has + been used in the choices option of a model field. + """ + response = self.client.get('/test_admin/admin/admin_views/fabric/') + self.failUnlessEqual(response.status_code, 200) + self.failUnless( + '<div id="changelist-filter">' in response.content, + "Expected filter not found in changelist view." + ) + self.failUnless( + '<a href="?surface__exact=x">Horizontal</a>' in response.content and + '<a href="?surface__exact=y">Vertical</a>' in response.content, + "Changelist filter isn't showing options contained inside a model field 'choices' option named group." + ) + def get_perm(Model, perm): """Return the permission object, for the Model""" ct = ContentType.objects.get_for_model(Model) |
