为什么 Django admin Short_description 功能不起作用?
我正在尝试对我的Django管理面板进行一些更改,例如想要显示“标题”而不是“ blog_tile”,但我不明白为什么不反映变化。
class BlogAdmin(admin.ModelAdmin):
readonly_fields = ['blog_publish_time', 'blog_update_time']
list_display = ['blog_title', 'blog_status',
'blog_publish_time', 'blog_update_time']
def rename_blog_title(self, obj):
return obj.blog_title[:10]
rename_blog_title.short_description = "title"
admin.site.register(Blog, BlogAdmin)
我在哪里做错?
I am trying to make some changes in my django admin panel such as want to show "title" instead of "blog_tile" but I am not understanding why changes not reflecting.
class BlogAdmin(admin.ModelAdmin):
readonly_fields = ['blog_publish_time', 'blog_update_time']
list_display = ['blog_title', 'blog_status',
'blog_publish_time', 'blog_update_time']
def rename_blog_title(self, obj):
return obj.blog_title[:10]
rename_blog_title.short_description = "title"
admin.site.register(Blog, BlogAdmin)
where I am doing mistake?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在
list_display
中使用的是blog_title
,而不是rename_blog_title
。因此,您应该引用该方法,而不是Blog
模型的字段:You are using
blog_title
, notrename_blog_title
in yourlist_display
. You thus should refer to the method, not to the field of yourBlog
model: