重写list_display在Django管理与定制的详细名称
问题描述:
我已经覆盖了list_display显示内嵌领域是这样的:重写list_display在Django管理与定制的详细名称
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管理,内联字段的显示名称头使用的功能名称:分别为联系人,电话和地址。其实我想用自定义文本显示这些字段标题。我甚至想用中文来展示他们。我错过了什么?
答
你需要定义你的功能short_description
属性:https://docs.djangoproject.com/en/stable/ref/contrib/admin/actions/#writing-action-functions
例如:
Contact.short_description = 'foo'
谢谢,它的工作原理完全和更准确的说Contact.short_description =“富”应在功能后添加到类中 – 2013-03-07 10:09:56