7

我已经覆盖了 list_display 以显示这样的内联字段:

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])

我的问题是,在 Django admin 中,内联字段标题的显示名称分别使用了函数名称:联系人、电话和地址。实际上我想用自定义文本显示那些字段标题。我什至想用中文来显示它们。我错过了什么?

4

1 回答 1

19

您需要short_description在函数上定义属性:https ://docs.djangoproject.com/en/stable/ref/contrib/admin/actions/#writing-action-functions

例如:

Contact.short_description = 'foo'

于 2013-03-01T17:31:03.243 回答