#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.e411664b4e4702c7a405f80b369a2b39%40djangoproject.com.

Reply via email to