summaryrefslogtreecommitdiff
path: root/tests/regressiontests/admin_views/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/regressiontests/admin_views/tests.py')
-rw-r--r--tests/regressiontests/admin_views/tests.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index ff97acd878..eca8adedc9 100644
--- a/tests/regressiontests/admin_views/tests.py
+++ b/tests/regressiontests/admin_views/tests.py
@@ -36,7 +36,7 @@ from models import (Article, BarAccount, CustomArticle, EmptyModel,
Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit,
Category, Post, Plot, FunkyTag, Chapter, Book, Promo, WorkHour, Employee,
Question, Answer, Inquisition, Actor, FoodDelivery,
- RowLevelChangePermissionModel, Paper, CoverLetter)
+ RowLevelChangePermissionModel, Paper, CoverLetter, Story, OtherStory)
class AdminViewBasicTest(TestCase):
@@ -1678,6 +1678,36 @@ class AdminViewListEditable(TestCase):
response = self.client.get('/test_admin/admin/admin_views/person/?%s' % IS_POPUP_VAR)
self.assertEqual(response.context['cl'].list_editable, ())
+ def test_pk_hidden_fields(self):
+ """ Ensure that hidden pk fields aren't displayed in the table body and
+ that their corresponding human-readable value is displayed instead.
+ Note that the hidden pk fields are in fact be displayed but
+ separately (not in the table), and only once.
+ Refs #12475.
+ """
+ Story.objects.create(title='The adventures of Guido', content='Once upon a time in Djangoland...')
+ Story.objects.create(title='Crouching Tiger, Hidden Python', content='The Python was sneaking into...')
+ response = self.client.get('/test_admin/admin/admin_views/story/')
+ self.assertContains(response, 'id="id_form-0-id"', 1) # Only one hidden field, in a separate place than the table.
+ self.assertContains(response, 'id="id_form-1-id"', 1)
+ self.assertContains(response, '<div class="hiddenfields">\n<input type="hidden" name="form-0-id" value="2" id="id_form-0-id" /><input type="hidden" name="form-1-id" value="1" id="id_form-1-id" />\n</div>')
+ self.assertContains(response, '<td>1</td>', 1)
+ self.assertContains(response, '<td>2</td>', 1)
+
+ def test_pk_hidden_fields_with_list_display_links(self):
+ """ Similarly as test_pk_hidden_fields, but when the hidden pk fields are
+ referenced in list_display_links.
+ Refs #12475.
+ """
+ OtherStory.objects.create(title='The adventures of Guido', content='Once upon a time in Djangoland...')
+ OtherStory.objects.create(title='Crouching Tiger, Hidden Python', content='The Python was sneaking into...')
+ response = self.client.get('/test_admin/admin/admin_views/otherstory/')
+ self.assertContains(response, 'id="id_form-0-id"', 1) # Only one hidden field, in a separate place than the table.
+ self.assertContains(response, 'id="id_form-1-id"', 1)
+ self.assertContains(response, '<div class="hiddenfields">\n<input type="hidden" name="form-0-id" value="2" id="id_form-0-id" /><input type="hidden" name="form-1-id" value="1" id="id_form-1-id" />\n</div>')
+ self.assertContains(response, '<th><a href="1/">1</a></th>', 1)
+ self.assertContains(response, '<th><a href="2/">2</a></th>', 1)
+
class AdminSearchTest(TestCase):
fixtures = ['admin-views-users', 'multiple-child-classes',