[Django] #33352: ModelAdmin.list_display option should support double-underscore notation to express field-of-associated-model

12 views
Skip to first unread message

Django

unread,
Dec 9, 2021, 12:47:36 PM12/9/21
to django-...@googlegroups.com
#33352: ModelAdmin.list_display option should support double-underscore notation to
express field-of-associated-model
-----------------------------------------+------------------------
Reporter: odigity | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: 4.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Many of the options on ModelAdmin already support double-underscore
notation, such as 'ordering' and 'search_fields':

https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.search_fields

However, 'list_display' doesn't. This seems like an extremely common use
case that everyone would benefit from. For example, imagine I have the
following models:

{{{
class User(models.Model):
name = models.CharField(max_length=50)

class CreditCard(models.Model):
owner = models.ForeignKey(User)
label = models.CharField(max_length=30)
limit = models.IntegerField()
}}}

And wanted to include the credit card owner's name as a column on the
Changelist page for CreditCard. Right now I have to do this:

{{{
class CreditCardAdmin(admin.ModelAdmin):
list_display = [ 'owner_name', 'label', 'limit' ]

@admin.display(ordering='owner__name', description='Owner')
def owner_name(self, obj):
return obj.owner.name
}}}

Instead of just doing this:

{{{
class CreditCardAdmin(admin.ModelAdmin):
list_display = [ 'owner__name', 'label', 'limit' ]
}}}

BTW - A version of this is already implemented in the
[https://pypi.org/project/django-related-admin/ django-related-admin]
package:
https://github.com/PetrDlouhy/django-related-admin/

--
Ticket URL: <https://code.djangoproject.com/ticket/33352>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 9, 2021, 1:29:21 PM12/9/21
to django-...@googlegroups.com
#33352: ModelAdmin.list_display option should support double-underscore notation to
express field-of-associated-model
-------------------------------+--------------------------------------
Reporter: Ofer Nave | Owner: nobody

Type: New feature | Status: new
Component: contrib.admin | Version: 4.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Adam Johnson):

* cc: Adam Johnson (added)


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

Django

unread,
Dec 9, 2021, 2:02:59 PM12/9/21
to django-...@googlegroups.com
#33352: ModelAdmin.list_display option should support double-underscore notation to
express field-of-associated-model
-------------------------------+--------------------------------------
Reporter: Ofer Nave | Owner: nobody
Type: New feature | Status: closed
Component: contrib.admin | Version: 4.0
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #10743.

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

Reply all
Reply to author
Forward
0 new messages