Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading