From 6a7a230964c8bec74db08404ac297c53ba14b47a Mon Sep 17 00:00:00 2001 From: Andrey <56235826+markdrrr@users.noreply.github.com> Date: Thu, 28 Dec 2023 19:43:56 +0300 Subject: [PATCH] Fix `TemplateDoesNotExist` when using `django-nested-admin` by returning custom template for other third-party packages. #341 (#342) --- admin_interface/templatetags/admin_interface_tags.py | 3 +++ tests/test_templatetags.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/admin_interface/templatetags/admin_interface_tags.py b/admin_interface/templatetags/admin_interface_tags.py index b6f0b83..011aa07 100644 --- a/admin_interface/templatetags/admin_interface_tags.py +++ b/admin_interface/templatetags/admin_interface_tags.py @@ -74,6 +74,9 @@ def get_admin_interface_setting(setting): @register.simple_tag() def get_admin_interface_inline_template(template): template_path = template.split("/") + if template_path[0] != "admin": + # return costume inline template for other packages + return template template_path[-1] = "headerless_" + template_path[-1] return "/".join(template_path) diff --git a/tests/test_templatetags.py b/tests/test_templatetags.py index 28c6da8..442ba1e 100644 --- a/tests/test_templatetags.py +++ b/tests/test_templatetags.py @@ -131,6 +131,10 @@ class AdminInterfaceTemplateTagsTestCase(TestCase): "admin/edit_inline/stacked.html" ) self.assertEqual(headless_template, "admin/edit_inline/headerless_stacked.html") + headless_template = templatetags.get_admin_interface_inline_template( + "nesting/admin/inlines/tabular.html" + ) + self.assertEqual(headless_template, "nesting/admin/inlines/tabular.html") def test_get_active_date_hierarchy_none(self): changelist = Mock()