[Django] #36539: Label for related fields should use related model verbose_name attribute for field

9 views
Skip to first unread message

Django

unread,
Aug 4, 2025, 12:48:31 PMAug 4
to django-...@googlegroups.com
#36539: Label for related fields should use related model verbose_name attribute
for field
-------------------------------------+-------------------------------------
Reporter: Leandro de Souza | Type:
| Uncategorized
Status: new | Component:
| contrib.admin
Version: 5.2 | Severity: Normal
Keywords: list_display, | Triage Stage:
fieldsets | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Django 5.1 has added support for referencing related fields directly from
the list_display/fieldsets option on the
django.contrib.admin.options.ModelAdmin class (#10743).
However, when referencing this field, the label generated for this field
is using the attribute name instead of the verbose_name defined on that
field.
Using the verbose_name would make much more sense and would be a great
addition.

Example:


{{{

# books/models.py
from django.db import models

class Author(models.Model):
name = models.CharField(verbose_name="Name of the author")


class Book(models.Model):
author = models.ForeignKey(to=Author, on_delete=models.PROTECT)



# books/admin.py

from django.contrib import admin
from .models import Book

@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
list_display = ("author__name",)

}}}


The above code would display on the change_list page: "Author name"
instead of the verbose_name defined at the `author.name` field.
The same applies to fieldsets used on the change page.
--
Ticket URL: <https://code.djangoproject.com/ticket/36539>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 4, 2025, 1:33:34 PMAug 4
to django-...@googlegroups.com
#36539: Label for related fields should use related model verbose_name attribute
for field
-------------------------------------+-------------------------------------
Reporter: Leandro de Souza | Owner: (none)
Type: Uncategorized | Status: new
Component: contrib.admin | Version: 5.2
Severity: Normal | Resolution:
Keywords: list_display, | Triage Stage:
fieldsets | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Leandro de Souza):

Just in time..
I've managed to create a monkey patched version with the changes required
for this to work.
I would be happy to submit a patch for this ticket if desired, this can
also include supporting casting related fields to their "choice" human
readable value using .get_fieldname_display
--
Ticket URL: <https://code.djangoproject.com/ticket/36539#comment:1>

Django

unread,
Aug 4, 2025, 1:58:40 PMAug 4
to django-...@googlegroups.com
#36539: Label for related fields should use related model verbose_name attribute
for field
-------------------------------------+-------------------------------------
Reporter: Leandro de Souza | Owner: Leandro
Type: | de Souza
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: list_display, | Triage Stage: Accepted
fieldsets |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* owner: (none) => Leandro de Souza
* stage: Unreviewed => Accepted
* status: new => assigned
* type: Uncategorized => Cleanup/optimization
* version: 5.2 => dev

Comment:

Hello Leandro de Souza, thank you for creating this ticket. I think this
is a good improvement, I'm looking forward to your contribution.
--
Ticket URL: <https://code.djangoproject.com/ticket/36539#comment:2>

Django

unread,
Aug 4, 2025, 2:22:46 PMAug 4
to django-...@googlegroups.com
#36539: Label for related fields should use related model verbose_name attribute
for field
-------------------------------------+-------------------------------------
Reporter: Leandro de Souza | Owner: Leandro
Type: | de Souza
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: list_display, | Triage Stage: Accepted
fieldsets |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Natalia Bidart):

Fix should be along these lines:
{{{ #!diff
diff --git a/django/contrib/admin/utils.py b/django/contrib/admin/utils.py
index 74bd571e56..23a6b36b9c 100644
--- a/django/contrib/admin/utils.py
+++ b/django/contrib/admin/utils.py
@@ -394,6 +394,8 @@ def label_for_field(name, model, model_admin=None,
return_attr=False, form=None)

if hasattr(attr, "short_description"):
label = attr.short_description
+ elif hasattr(attr, "verbose_name"):
+ label = attr.verbose_name
elif (
isinstance(attr, property)
and hasattr(attr, "fget")
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36539#comment:3>

Django

unread,
Aug 4, 2025, 2:32:32 PMAug 4
to django-...@googlegroups.com
#36539: Label for related fields should use related model verbose_name attribute
for field
-------------------------------------+-------------------------------------
Reporter: Leandro de Souza | Owner: Leandro
Type: | de Souza
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: list_display, | Triage Stage: Accepted
fieldsets |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Leandro de Souza):

* has_patch: 0 => 1

Comment:

[https://github.com/django/django/pull/19704 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/36539#comment:4>

Django

unread,
Aug 4, 2025, 2:36:54 PMAug 4
to django-...@googlegroups.com
#36539: Label for related fields should use related model verbose_name attribute
for field
-------------------------------------+-------------------------------------
Reporter: Leandro de Souza | Owner: Leandro
Type: | de Souza
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: list_display, | Triage Stage: Accepted
fieldsets |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Leandro de Souza):

Just opened the PR, probably will break some tests, will fix them some
time soon.
--
Ticket URL: <https://code.djangoproject.com/ticket/36539#comment:5>

Django

unread,
Aug 4, 2025, 4:49:40 PMAug 4
to django-...@googlegroups.com
#36539: Label for related fields should use related model verbose_name attribute
for field
-------------------------------------+-------------------------------------
Reporter: Leandro de Souza | Owner: Leandro
Type: | de Souza
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: list_display, | Triage Stage: Accepted
fieldsets |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Leandro de Souza):

Looks like all tests that should've run are ok. Let me know if any changes
are needed
--
Ticket URL: <https://code.djangoproject.com/ticket/36539#comment:6>

Django

unread,
Aug 4, 2025, 5:06:36 PMAug 4
to django-...@googlegroups.com
#36539: Label for related fields should use related model verbose_name attribute
for field
-------------------------------------+-------------------------------------
Reporter: Leandro de Souza | Owner: Leandro
Type: | de Souza
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: list_display, | Triage Stage: Accepted
fieldsets |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* needs_tests: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36539#comment:7>

Django

unread,
Aug 14, 2025, 10:17:38 PMAug 14
to django-...@googlegroups.com
#36539: Label for related fields should use related model verbose_name attribute
for field
-------------------------------------+-------------------------------------
Reporter: Leandro de Souza | Owner: Leandro
Type: | de Souza
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: list_display, | Triage Stage: Accepted
fieldsets |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* needs_tests: 1 => 0

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

Django

unread,
Aug 22, 2025, 9:38:09 AMAug 22
to django-...@googlegroups.com
#36539: Label for related fields should use related model verbose_name attribute
for field
-------------------------------------+-------------------------------------
Reporter: Leandro de Souza | Owner: Leandro
Type: | de Souza
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: list_display, | Triage Stage: Accepted
fieldsets |
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/36539#comment:9>
Reply all
Reply to author
Forward
0 new messages