From 84609b3205905097d7d3038d32e6101f012c0619 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Tue, 8 Sep 2020 15:39:43 -0700 Subject: [PATCH] Fixed #31993 -- Added subtitles to admin change/view pages. --- django/contrib/admin/options.py | 2 + .../contrib/admin/templates/admin/base.html | 1 + .../admin/templates/admin/base_site.html | 2 +- tests/admin_views/tests.py | 57 ++++++++++++++++++- 4 files changed, 59 insertions(+), 3 deletions(-) diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 2b02de84e47..bea685966e7 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -1627,6 +1627,7 @@ class ModelAdmin(BaseModelAdmin): context = { **self.admin_site.each_context(request), 'title': title % opts.verbose_name, + 'subtitle': str(obj) if obj else None, 'adminform': adminForm, 'object_id': object_id, 'original': obj, @@ -1815,6 +1816,7 @@ class ModelAdmin(BaseModelAdmin): 'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)}, 'selection_note_all': selection_note_all % {'total_count': cl.result_count}, 'title': cl.title, + 'subtitle': None, 'is_popup': cl.is_popup, 'to_field': cl.to_field, 'cl': cl, diff --git a/django/contrib/admin/templates/admin/base.html b/django/contrib/admin/templates/admin/base.html index 3f39cd5b8f5..d86f138da51 100644 --- a/django/contrib/admin/templates/admin/base.html +++ b/django/contrib/admin/templates/admin/base.html @@ -86,6 +86,7 @@
{% block pretitle %}{% endblock %} {% block content_title %}{% if title %}

{{ title }}

{% endif %}{% endblock %} + {% block content_subtitle %}{% if subtitle %}

{{ subtitle }}

{% endif %}{% endblock %} {% block content %} {% block object-tools %}{% endblock %} {{ content }} diff --git a/django/contrib/admin/templates/admin/base_site.html b/django/contrib/admin/templates/admin/base_site.html index cae0a691e36..9e8cc604c59 100644 --- a/django/contrib/admin/templates/admin/base_site.html +++ b/django/contrib/admin/templates/admin/base_site.html @@ -1,6 +1,6 @@ {% extends "admin/base.html" %} -{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %} +{% block title %}{% if subtitle %}{{ subtitle }} | {% endif %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %} {% block branding %}

{{ site_header|default:_('Django administration') }}

diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 62aa236e2b7..61894de9f00 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -100,10 +100,16 @@ class AdminViewBasicTestCase(TestCase): cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com') cls.s1 = Section.objects.create(name='Test section') cls.a1 = Article.objects.create( - content='

Middle content

', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1 + content='

Middle content

', + date=datetime.datetime(2008, 3, 18, 11, 54, 58), + section=cls.s1, + title='Article 1', ) cls.a2 = Article.objects.create( - content='

Oldest content

', date=datetime.datetime(2000, 3, 18, 11, 54, 58), section=cls.s1 + content='

Oldest content

', + date=datetime.datetime(2000, 3, 18, 11, 54, 58), + section=cls.s1, + title='Article 2', ) cls.a3 = Article.objects.create( content='

Newest content

', date=datetime.datetime(2009, 3, 18, 11, 54, 58), section=cls.s1 @@ -1027,6 +1033,53 @@ class AdminViewBasicTest(AdminViewBasicTestCase): self.assertContains(response, '') self.assertNotContains(response, '