Changes between Initial Version and Version 1 of Ticket #36114, comment 4


Ignore:
Timestamp:
Jan 19, 2025, 5:24:58 PM (5 weeks ago)
Author:
Antoliny

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #36114, comment 4

    initial v1  
    33
    44I think that a `__str__` value being composed entirely of blank spaces is extremely rare unless it's a user mistake. However, for fields, when they consist only of blank spaces, they are treated as `None` and return the default empty_value("-"). Similarly, when `__str__` is composed of only blank spaces, it should return a default empty_value like "-" so that it can function as a link when set in `list_display_links`.
    5 It seems that adding a bit of logic to the `item_for_result`(contrib.admin.templatetags.admin_list.py) function would suffice.
     5It seems that adding a bit of logic to the `item_for_result` function would suffice.
     6{{{#!diff
     7diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py
     8index 7a49587172..76dfda9d9e 100644
     9--- a/django/contrib/admin/templatetags/admin_list.py
     10+++ b/django/contrib/admin/templatetags/admin_list.py
     11@@ -226,6 +226,8 @@ def items_for_result(cl, result, form):
     12             if f is None or f.auto_created:
     13                 if field_name == "action_checkbox":
     14                     row_classes = ["action-checkbox"]
     15+                elif field_name == "__str__":
     16+                    value = value.strip()
     17                 boolean = getattr(attr, "boolean", False)
     18                 # Set boolean for attr that is a property, if defined.
     19                 if isinstance(attr, property) and hasattr(attr, "fget"):
     20
     21}}}
Back to Top