summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantoliny0919 <antoliny0919@gmail.com>2025-01-07 20:22:30 +0900
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-02-04 08:57:25 +0100
commit209d0f6143739df8583adb7e93856ad3584c9fdb (patch)
tree71b9b660fc88d9b213c3cc3a162956c52a83a9df
parentd03102a5a88c3666295ebb4d4d9d25b28bd374bb (diff)
[5.2.x] Fixed #36069 -- Fixed the delete button position in TabularInlines.
Backport of 1330cb570519170bb4397b4fb02c7e3e0657855a from main.
-rw-r--r--django/contrib/admin/templates/admin/edit_inline/tabular.html6
-rw-r--r--tests/admin_inlines/tests.py32
2 files changed, 34 insertions, 4 deletions
diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html b/django/contrib/admin/templates/admin/edit_inline/tabular.html
index 7acfda7bd1..9367ac9b63 100644
--- a/django/contrib/admin/templates/admin/edit_inline/tabular.html
+++ b/django/contrib/admin/templates/admin/edit_inline/tabular.html
@@ -23,7 +23,7 @@
{% if field.help_text %}<img src="{% static "admin/img/icon-unknown.svg" %}" class="help help-tooltip" width="10" height="10" alt="({{ field.help_text|striptags }})" title="{{ field.help_text|striptags }}">{% endif %}
</th>
{% endfor %}
- {% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission %}<th>{% translate "Delete?" %}</th>{% endif %}
+ <th>{% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission %}{% translate "Delete?" %}{% endif %}</th>
</tr></thead>
<tbody>
@@ -58,9 +58,7 @@
{% endfor %}
{% endfor %}
{% endfor %}
- {% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission %}
- <td class="delete">{% if inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}{% endif %}</td>
- {% endif %}
+ <td class="delete">{% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission and inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}{% endif %}</td>
</tr>
{% endfor %}
</tbody>
diff --git a/tests/admin_inlines/tests.py b/tests/admin_inlines/tests.py
index b08ab3a52a..89f43300d7 100644
--- a/tests/admin_inlines/tests.py
+++ b/tests/admin_inlines/tests.py
@@ -19,6 +19,7 @@ from .models import (
Child,
ChildModel1,
ChildModel2,
+ ExtraTerrestrial,
Fashionista,
FootNote,
Holder,
@@ -2493,3 +2494,34 @@ class SeleniumTests(AdminSeleniumTestCase):
tabular_inline.find_elements(By.CSS_SELECTOR, ".collapse"),
[],
)
+
+ @screenshot_cases(["desktop_size", "mobile_size", "rtl", "dark", "high_contrast"])
+ def test_tabular_inline_delete_layout(self):
+ from selenium.webdriver.common.by import By
+
+ user = User.objects.create_user("testing", password="password", is_staff=True)
+ et_permission = Permission.objects.filter(
+ content_type=ContentType.objects.get_for_model(ExtraTerrestrial),
+ )
+ s_permission = Permission.objects.filter(
+ codename__in=["view_sighting", "add_sighting"],
+ content_type=ContentType.objects.get_for_model(Sighting),
+ )
+ user.user_permissions.add(*et_permission, *s_permission)
+ self.admin_login(username="testing", password="password")
+ cf = ExtraTerrestrial.objects.create(name="test")
+ url = reverse("admin:admin_inlines_extraterrestrial_change", args=(cf.pk,))
+ self.selenium.get(self.live_server_url + url)
+ headers = self.selenium.find_elements(
+ By.CSS_SELECTOR, "fieldset.module thead tr th"
+ )
+ self.assertHTMLEqual(headers[-1].get_attribute("outerHTML"), "<th></th>")
+ delete = self.selenium.find_element(
+ By.CSS_SELECTOR,
+ "fieldset.module tbody tr.dynamic-sighting_set:not(.original) td.delete",
+ )
+ self.assertIn(
+ '<a role="button" class="inline-deletelink" href="#">',
+ delete.get_attribute("innerHTML"),
+ )
+ self.take_screenshot("loaded")