我已经覆盖了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])
Run Code Online (Sandbox Code Playgroud)
我的问题是,在Django admin中,内联字段标题的显示名称分别使用了函数名称:Contact,Phone和Address.实际上我想用自定义文本显示那些字段标题.我甚至想用中文来展示它们.我错过了什么?
Abi*_*d A 18
您需要short_description在函数上定义属性:https://docs.djangoproject.com/en/stable/ref/contrib/admin/actions/#writing-action-functions
例如:
Contact.short_description = 'foo'
| 归档时间: |
|
| 查看次数: |
6128 次 |
| 最近记录: |