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.
* cc: Adam Johnson (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/33352#comment:1>
* status: new => closed
* resolution: => duplicate
Comment:
Duplicate of #10743.
--
Ticket URL: <https://code.djangoproject.com/ticket/33352#comment:2>