#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 Antoliny):

 I explored several approaches to address this issue.
 I initially wanted to solve it using conditions directly in the template,
 but there was no suitable attribute available to determine whether each
 Formset contains objects.

 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.
 {{{#!diff
 diff --git a/django/contrib/admin/helpers.py
 b/django/contrib/admin/helpers.py
 index 51450d1d9e..97a9f764f1 100644
 --- a/django/contrib/admin/helpers.py
 +++ b/django/contrib/admin/helpers.py
 @@ -337,6 +337,7 @@ class InlineAdminFormSet:
          self.has_change_permission = has_change_permission
          self.has_delete_permission = has_delete_permission
          self.has_view_permission = has_view_permission
 +        self.has_object = self.formset.get_queryset().exists()

      def __iter__(self):
          if self.has_change_permission:
 diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html
 b/django/contrib/admin/templates/admin/edit_inline/tabular.html
 index 7acfda7bd1..e1c7d993b5 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.formset.can_delete and
 inline_admin_formset.has_delete_permission and
 inline_admin_formset.has_object %}<th>{% translate "Delete?" %}</th>{%
 endif %}
       </tr></thead>

       <tbody>
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36067#comment:3>
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/0107019440024035-0c95e2a7-c271-4194-9f6a-ecde39fa7e3c-000000%40eu-central-1.amazonses.com.

Reply via email to