[Django]-Django admin – how to display thumbnail instead of path to file

18👍

I’ve solved this by adding:

def image_thumb(self):
    return '<img src="/media/%s" width="100" height="100" />' % (self.photo)
image_thumb.allow_tags = True

to the model in models.py

5👍

There have been some fairly detailed answers to this question in the past, try this link.

Django admin and showing thumbnail images

👤zzbomb

4👍

By the way, for all noobies like me:
It works also in StackedInline and TabularInline, but if you use this solution, you should add in admin.py:

fields = (..., 'image_thumb', ...) # as you have expected
readonly_fields = ['image_thumb'] # without this there will be traceback
👤McGrog

Leave a comment