Django: Display image in admin interface

前端 未结 7 1850
盖世英雄少女心
盖世英雄少女心 2020-11-28 23:00

I\'ve defined a model which contains a link an image. Is there a way to display the image in the model items list? My model looks like this:

class Article(mo         


        
7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 23:21

    def image_tag(self, obj):
        return u'' % obj.image
    
    image_tag.short_description = 'Image'
    image_tag.allow_tags = True
    

    and in your admin.py add:

       readonly_fields = ('image_tag',)
    

提交回复
热议问题