Django admin and showing thumbnail images

前端 未结 6 1701
春和景丽
春和景丽 2020-12-04 06:19

I\'m trying to show thumbnail images in Django admin, but I can only see the path to the images, but not the rendered images. I don\'t know what I\'m doing wrong.

Se

6条回答
  •  忘掉有多难
    2020-12-04 06:30

    Update v. 1.9

    Note that in Django v.1.9

    image_tag.allow_tags = True
    

    is depricated and you should use format_html(), format_html_join(), or mark_safe() instead

    So your model.py should look like this:

    ...
    def image_img(self):
        if self.image:
            return marksafe('' % self.image.url_125x125)
        else:
            return '(Sin imagen)'
        image_img.short_description = 'Thumb'
    

    and in your admin.py add:

    list_display= ('image_img','product',)
    readonly_fields = ('image_img',)
    

    and for adding it in the 'Edit mode' of your admin panel in your admin.py add:

    fields = ( 'image_img', )
    

提交回复
热议问题