'why Django admin short_description function not working?
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?
Solution 1:[1]
You are using blog_title, not rename_blog_title in your list_display. You thus should refer to the method, not to the field of your Blog model:
class BlogAdmin(admin.ModelAdmin):
readonly_fields = ['blog_publish_time', 'blog_update_time']
list_display = ['rename_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)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Willem Van Onsem |
