Foreign Key Reference for Django in Admin

谁说我不能喝 提交于 2019-12-04 08:38:07
Wtower

You can use a custom method in the admin class as:

class PostAdmin(admin.ModelAdmin):

    list_display = ['title', 'author', 'author_description']

    def author_description(self, obj):
        return obj.author.get_author_description()

Additionally, you can custom format a field or a property within the custom method. If the method would return HTML, you could add the following, after the method, in the class:

author_description.allow_tags = True

Last, if you would like to add a custom verbose name for this method:

author_description.short_description = "My awesome name"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!