[Django] #36114: when an object's __str__ consists only of whitespace, the link does not appear in admin list page.

24 views
Skip to first unread message

Django

unread,
Jan 19, 2025, 6:21:21 AM1/19/25
to django-...@googlegroups.com
#36114: when an object's __str__ consists only of whitespace, the link does not
appear in admin list page.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Type: Bug
Status: new | Component:
| contrib.admin
Version: 5.1 | Severity: Normal
Keywords: list_display_links, | Triage Stage:
list_display | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
In the admin list page, when the value of `list_display` is set to
'__str__' (default option), if the model's `__str__` is composed entirely
of blank values, the link will not appear.
{{{
class Post(models.Model):
title = models.CharField(max_length=128)
content = models.TextField()
like = models.IntegerField(default=0)

def __str__(self):
return " "
}}}
[[Image(blank.png)]]
In a typical situation it would be fine, but when `__str__` is set in
`list_display_links`, <a> tag innerHTML becomes empty, so resulting in the
loss of the link functionality to navigate to the object.
{{{
class PostAdmin(admin.ModelAdmin):
list_display_links = ["__str__"]
list_display = ["__str__", "title"]
}}}
[[Image(str_blank.png)]]
--
Ticket URL: <https://code.djangoproject.com/ticket/36114>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 19, 2025, 6:21:29 AM1/19/25
to django-...@googlegroups.com
#36114: when an object's __str__ consists only of whitespace, the link does not
appear in admin list page.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: 5.1
Severity: Normal | Resolution:
Keywords: list_display_links, | Triage Stage:
list_display | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* Attachment "str_blank.png" added.

Django

unread,
Jan 19, 2025, 6:21:30 AM1/19/25
to django-...@googlegroups.com
#36114: when an object's __str__ consists only of whitespace, the link does not
appear in admin list page.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: 5.1
Severity: Normal | Resolution:
Keywords: list_display_links, | Triage Stage:
list_display | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* Attachment "balnk.png" added.

Django

unread,
Jan 19, 2025, 6:21:47 AM1/19/25
to django-...@googlegroups.com
#36114: when an object's __str__ consists only of whitespace, the link does not
appear in admin list page.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Bug | Status: assigned
Component: contrib.admin | Version: 5.1
Severity: Normal | Resolution:
Keywords: list_display_links, | Triage Stage:
list_display | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* owner: (none) => Antoliny
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36114#comment:1>

Django

unread,
Jan 19, 2025, 6:22:09 AM1/19/25
to django-...@googlegroups.com
#36114: when an object's __str__ consists only of whitespace, the link does not
appear in admin list page.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Bug | Status: assigned
Component: contrib.admin | Version: 5.1
Severity: Normal | Resolution:
Keywords: list_display_links, | Triage Stage:
list_display | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Antoliny:

Old description:

> In the admin list page, when the value of `list_display` is set to
> '__str__' (default option), if the model's `__str__` is composed entirely
> of blank values, the link will not appear.
> {{{
> class Post(models.Model):
> title = models.CharField(max_length=128)
> content = models.TextField()
> like = models.IntegerField(default=0)
>
> def __str__(self):
> return " "
> }}}
> [[Image(blank.png)]]
> In a typical situation it would be fine, but when `__str__` is set in
> `list_display_links`, <a> tag innerHTML becomes empty, so resulting in
> the loss of the link functionality to navigate to the object.
> {{{
> class PostAdmin(admin.ModelAdmin):
> list_display_links = ["__str__"]
> list_display = ["__str__", "title"]
> }}}
> [[Image(str_blank.png)]]

New description:

In the admin list page, when the value of `list_display` is set to
'__str__' (default option), if the model's `__str__` is composed entirely
of blank values, the link will not appear.
{{{
class Post(models.Model):
title = models.CharField(max_length=128)
content = models.TextField()
like = models.IntegerField(default=0)

def __str__(self):
return " "
}}}
[[Image(balnk.png)]]
In a typical situation it would be fine, but when `__str__` is set in
`list_display_links`, <a> tag innerHTML becomes empty, so resulting in the
loss of the link functionality to navigate to the object.
{{{
class PostAdmin(admin.ModelAdmin):
list_display_links = ["__str__"]
list_display = ["__str__", "title"]
}}}
[[Image(str_blank.png)]]

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36114#comment:2>

Django

unread,
Jan 19, 2025, 2:26:47 PM1/19/25
to django-...@googlegroups.com
#36114: when an object's __str__ consists only of whitespace, the link does not
appear in admin list page.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Bug | Status: assigned
Component: contrib.admin | Version: 5.1
Severity: Normal | Resolution:
Keywords: list_display_links, | Triage Stage:
list_display | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Tim Graham):

What's the use case for str being a blank value and what is your proposal
to fix it?
--
Ticket URL: <https://code.djangoproject.com/ticket/36114#comment:3>

Django

unread,
Jan 19, 2025, 5:55:03 PM1/19/25
to django-...@googlegroups.com
#36114: when an object's __str__ consists only of whitespace, the link does not
appear in admin list page.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Bug | Status: assigned
Component: contrib.admin | Version: 5.1
Severity: Normal | Resolution:
Keywords: list_display_links, | Triage Stage:
list_display | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Antoliny):

Replying to [comment:3 Tim Graham]:
> What's the use case for str being a blank value and what is your
proposal to fix it?

I 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`.
It seems that adding a bit of logic to the
`item_for_result`(contrib.admin.templatetags.admin_list.py) function would
suffice.
--
Ticket URL: <https://code.djangoproject.com/ticket/36114#comment:4>

Django

unread,
Jan 19, 2025, 7:53:15 PM1/19/25
to django-...@googlegroups.com
#36114: when an object's __str__ consists only of whitespace, the link does not
appear in admin list page.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Bug | Status: assigned
Component: contrib.admin | Version: 5.1
Severity: Normal | Resolution:
Keywords: list_display_links, | Triage Stage: Accepted
list_display |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Accepted

--
Ticket URL: <https://code.djangoproject.com/ticket/36114#comment:5>

Django

unread,
Jan 21, 2025, 2:21:38 AM1/21/25
to django-...@googlegroups.com
#36114: when an object's __str__ consists only of whitespace, the link does not
appear in admin list page.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Bug | Status: assigned
Component: contrib.admin | Version: 5.1
Severity: Normal | Resolution:
Keywords: list_display_links, | Triage Stage: Accepted
list_display |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36114#comment:6>

Django

unread,
Jan 21, 2025, 2:26:34 AM1/21/25
to django-...@googlegroups.com
#36114: when an object's __str__ consists only of whitespace, the link does not
appear in admin list page.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Bug | Status: assigned
Component: contrib.admin | Version: 5.1
Severity: Normal | Resolution:
Keywords: list_display_links, | Triage Stage: Accepted
list_display |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Antoliny):

[https://github.com/django/django/pull/19078 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/36114#comment:7>

Django

unread,
Jan 21, 2025, 4:06:33 AM1/21/25
to django-...@googlegroups.com
#36114: when an object's __str__ consists only of whitespace, the link does not
appear in admin list page.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Bug | Status: assigned
Component: contrib.admin | Version: 5.1
Severity: Normal | Resolution:
Keywords: list_display_links, | Triage Stage: Accepted
list_display |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36114#comment:8>

Django

unread,
Jan 21, 2025, 4:33:19 AM1/21/25
to django-...@googlegroups.com
#36114: when an object's __str__ consists only of whitespace, the link does not
appear in admin list page.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Bug | Status: assigned
Component: contrib.admin | Version: 5.1
Severity: Normal | Resolution:
Keywords: list_display_links, | Triage Stage: Accepted
list_display |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/36114#comment:9>
Reply all
Reply to author
Forward
0 new messages