Django admin listview 自定义列名 [英] Django admin listview Customize Column Name
问题描述
好的,所以我有一个从作者模型构建的自定义 django 管理员:
Ok so I have a custom django admin built from a Author Model:
class AuthorAdmin(admin.ModelAdmin):
"""
Author Admin
"""
form = AuthorForm
list_display = ['profile_photo', 'first_name', 'last_name', 'title']
search_fields = ['first_name', 'last_name', 'title', 'credential']
prepopulated_fields = {'slug': ('first_name', 'last_name', 'title')}
def profile_photo(self, obj) :
return '<img src="%s" title="%s" />' % (resize_image(obj.photo, '100x100'), obj.title)
profile_photo.allow_tags = True
但是在 django 管理列表视图中,自定义列的列标题没有正确的大写.
But in the django admin listview the column title for the custom column does not have proper capitalization.
有谁知道如何覆盖根据自定义函数名称构建的列标题?
Does anyone know how to override the column headers that are built from custom function's names?
我试过了:
def my_function(self, obj) :
"""My Custom Title"""
...
和
def my_function(self, obj) :
class Meta:
verbose_name = _(u"My Custom Title")
推荐答案
使用:
class AuthorAdmin(admin.ModelAdmin):
…
def my_function(self, obj) :
"""My Custom Title"""
…
my_function.short_description = 'This is the Column Name'
它隐藏在 admin文档.short_description
,具体来说,在list_display
的讨论中几乎没有被提及(更多是示例而不是实际调用).像这样的其他项目同样隐藏在管理文档中,但这里是一个摘要:
It's buried in the admin docs. short_description
, specifically, is barely mentioned under the discussion of list_display
(more by example than actually called out). The other items like this are similiarly buried in the admin docs, but here's a summary:
short_description
:要使用的列标题(字符串)allow_tags
:名称是什么意思...让我们使用 HTML(True
或False
)admin_order_field
:模型上的一个字段,用于按(字符串,字段名称)对该列进行排序boolean
:表示返回值为布尔值,并通知管理员使用漂亮的图形绿色对勾/红色 X(True
或False
)
short_description
: the column title to use (string)allow_tags
: what the name says... let's you use HTML (True
orFalse
)admin_order_field
: a field on the model to order this column by (string, field name)boolean
: indicates the return value is boolean and signals the admin to use the nice graphic green check/red X (True
orFalse
)
这篇关于Django admin listview 自定义列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!