[Fixed]-Adding Image into Django Admin ImageField and displaying it in html

1👍

How about adding an extra field in the admin class?

In admins.py:

from myapp.models import MyModel
from django.contrib.admin import register, ModelAdmin

@register MyModel
class MyAdmin(ModelAdmin):

    readonly_fields = ('image_preview',)

    def image_preview(self, obj):
        image_field = getattr(obj, 'image', '')
        return format_html(u'<img src="{}" />', image_field.url)
👤raphv

Leave a comment