Opened 3 hours ago

Last modified 3 hours ago

#36114 assigned Bug

when an object's __str__ consists only of whitespace, the link does not appear in admin list page.

Reported by: Antoliny Owned by: Antoliny
Component: contrib.admin Version: 5.1
Severity: Normal Keywords: list_display_links, list_display
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Antoliny)

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 "       "


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"]


Attachments (2)

str_blank.png (42.7 KB ) - added by Antoliny 3 hours ago.
balnk.png (44.4 KB ) - added by Antoliny 3 hours ago.

Download all attachments as: .zip

Change History (4)

by Antoliny, 3 hours ago

Attachment: str_blank.png added

by Antoliny, 3 hours ago

Attachment: balnk.png added

comment:1 by Antoliny, 3 hours ago

Owner: set to Antoliny
Status: newassigned

comment:2 by Antoliny, 3 hours ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top