#36067: Ambiguity of the 'DELETE' text when a TabularInline object does not
exist
--------------------------------------+------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: TabularInline | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Natalia Bidart):
Replying to [comment:3 Antoliny]:
> As a solution, I decided to add a self.has_object attribute to the
InlineAdminFormSet, assigning it the return value of
self.formset.get_queryset().exists(). This allows the presence of the
"DELETE?" text to be determined based on whether objects exist.
>
> However, the downside of this approach is that an attribute is being
added solely for the purpose of removing the "DELETE?" text. If you have a
better suggestion, I would greatly appreciate your advice.
I share your concern with your initial diff. There is one extra query
being issued which feels unnecessary. I played a bit with this and settled
on having something like this, which nicely reduces logic in the template
for calculating the header and checkbox row, and it also uses the existing
information in the formset:
{{{#!diff
diff --git a/django/contrib/admin/helpers.py
b/django/contrib/admin/helpers.py
index 51450d1d9e..3e33855394 100644
--- a/django/contrib/admin/helpers.py
+++ b/django/contrib/admin/helpers.py
@@ -460,6 +460,14 @@ class InlineAdminFormSet:
def total_form_count(self):
return self.formset.total_form_count
+ @property
+ def can_delete(self):
+ return (
+ self.formset.can_delete
+ and self.has_delete_permission
+ and any(inlineadminform.original is not None for
inlineadminform in self)
+ )
+
@property
def media(self):
media = self.opts.media + self.formset.media
diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html
b/django/contrib/admin/templates/admin/edit_inline/tabular.html
index 7acfda7bd1..ebbe3dfe25 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 %}
+ {% if inline_admin_formset.can_delete %}<th>{% translate "Delete?"
%}</th>{% endif %}
</tr></thead>
<tbody>
@@ -58,7 +58,7 @@
{% endfor %}
{% endfor %}
{% endfor %}
- {% if inline_admin_formset.formset.can_delete and
inline_admin_formset.has_delete_permission %}
+ {% if inline_admin_formset.can_delete %}
<td class="delete">{% if inline_admin_form.original %}{{
inline_admin_form.deletion_field.field }}{% endif %}</td>
{% endif %}
</tr>
}}}
Antoliny, what do you think? This would need a few tests added to existing
admin suite.
--
Ticket URL: <https://code.djangoproject.com/ticket/36067#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/01070194420b0f8c-ce90cf2d-d6cf-46aa-9f7f-7b6546220049-000000%40eu-central-1.amazonses.com.