Django admin listview自定义列名 [英] Django admin listview Customize Column Name
问题描述
好,所以我有一个自定义的django管理员从一个作者模型构建:
类AuthorAdmin(admin.ModelAdmin):
作者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 =%stitle =%s/>'%(resize_image(obj.photo, '100x100'),obj.title)
profile_photo.allow_tags = True
但在django管理列表中,自定义列的列标题没有正确的大小写。
有人知道如何覆盖从自定义函数名称构建的列标题?
我尝试过:
def my_function(self,obj):
/ pre>
我的自定义标题
...
和
def my_function(self,obj)
class Meta:
verbose_name = _(u我的自定义标题)
解决方案使用:
def my_function(self,obj):
我的自定义标题
...
my_function.short_description ='这是列名'
它被埋在管理员文档。
short_description
,特别是在list_display
的讨论中几乎没有提及(比实际调用的更多)。这样的其他项目类似地被埋在管理员文档中,但这里有一个摘要:
-
short_description
:要使用的列标题(字符串) -
allow_tags
:什么名称说...让我们用HTML (True
或False
) -
admin_order_field
:通过(字符串,字段名称)排序此列的模型字段 -
boolean
:表示返回值为布尔值,并指示管理员使用漂亮的图形绿色检查/红色X(True
或False
)
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
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?
I've tried:
def my_function(self, obj) :
"""My Custom Title"""
...
and
def my_function(self, obj) :
class Meta:
verbose_name = _(u"My Custom Title")
Use:
def my_function(self, obj) :
"""My Custom Title"""
...
my_function.short_description = 'This is the Column Name'
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
: 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屋!