我已经覆盖了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中,内联字段标题的显示名称分别使用了函数名称:Contact,Phone和Address。实际上我想用自定义文本显示那些字段标题。我甚至想用中文来展示它们。我错过了什么?
答案 0 :(得分:17)
您需要在功能上定义short_description
属性:https://docs.djangoproject.com/en/stable/ref/contrib/admin/actions/#writing-action-functions
例如:
Contact.short_description = 'foo'