Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding list_display in Django admin with custom verbose name

Tags:

python

django

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?

like image 449
Bill Kary Avatar asked Mar 01 '13 17:03

Bill Kary


1 Answers

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'

like image 146
Abid A Avatar answered Oct 27 '22 00:10

Abid A