Overriding list_display in Django admin with custom long name

I overridden list_display to display such inline fields:

class opportunityAdmin(admin.ModelAdmin): list_display = ('name', 'Contact', 'Phone', 'Address', 'discovery_date', 'status' , 'outcome') search_fields = ['name', 'tags' , 'description'] #readonly_fields = ('discovery_date','close_date') inlines = [account_contactInline, account_updateInline] def Contact(self, obj): return '<br/>'.join(c.account_poc for c in account_contact.objects.filter(opportunity=obj.id).order_by('id')[:1]) def Phone(self, obj): return '<br/>'.join(c.account_phone for c in account_contact.objects.filter(opportunity=obj.id).order_by('id')[:1]) def Address(self, obj): return '<br/>'.join(c.account_address for c in account_contact.objects.filter(opportunity=obj.id).order_by('id')[:1]) 

My question is that in Django admin, the display name of the header of the built-in fields used the function name: "Contact", "Phone" and "Address", respectively. Actually, I want to display this field title using custom text. I even want to use Chinese to display them. What did I miss?

+4
source share
1 answer

You will need to define a short_description attribute for your functions: https://docs.djangoproject.com/en/stable/ref/contrib/admin/actions/#writing-action-functions

For instance:

Contact.short_description = 'foo'

+15
source

All Articles