Bill Kary
Bill Kary

Reputation: 705

Overriding list_display in Django admin with custom verbose name

I have overridden the list_display to show inline fields like this:

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, in Django admin, the display name of the inline fields header used the function name: Contact, Phone and Address respectively. Actually i wanna display those field header with custom text. I even wanna use Chinese to display them. What have i missed?

Upvotes: 11

Views: 10761

Answers (1)

Abid A
Abid A

Reputation: 7858

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

For example:

Contact.short_description = 'foo'

Upvotes: 22

Related Questions