Django 管理员可以在模型名称后显示图像吗?

Can Django admin show the image after the model name?

我有问题。

我可以在 django 管理中的模型名称后添加图像吗?

The postion I want to add the picture.

我想在登录管理页面时看到图书图像

我不知道

也许我可以使用 verbose_name 注入 html 标签?

django可以吗?或者我应该用其他方式来做?

基本上,您可以在 Django admin list view 中自定义 ModelAdmin.list_display,例如:

假设您有一个模型 MyModel,其图像字段名为 image

from django.utils.html import format_html

@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
    list_display = ('id', <b>'image_tag'</b>)

    def image_tag(self, obj):
        <b>return format_html("<img src="{}" width=200 height=80/>'.format(obj.image.url))</b>
    image_tag.short_description = 'Image'