1

I'm trying to show the images from my model within the Django Admin:

class RewardAdmin(admin.ModelAdmin):
    list_display = ('name', 'company', 'offer_image')

I'm using Django Storages and images are stored in S3. But the images don't show (see image)...

enter image description here

I have tried by adding the following model method

def offer_image(self):

   return '<img src={} style="height: 100px;"/>'.format(self.offer_image)

How can I get this to work?

Is there a version of request.build_absolute_uri() that I can use?

Prometheus
  • 32,405
  • 54
  • 166
  • 302

1 Answers1

2

I have done something similar in the past. You go in your model and do something like this:

def image_img(self):
        if self.offer_image:
            return u'<img src="%s"  height="100px"/>' % self.offer_image
        else:
            return 'No_image'
image_img.short_description = 'Image'
image_img.allow_tags = True

Then, in the admin of the app you include the 'image_img' in the list_display list :)

Bogdan Goie
  • 1,257
  • 1
  • 13
  • 21
  • It is almost the same answer to http://stackoverflow.com/questions/1385094/django-admin-and-showing-thumbnail-images and it is being upvoted. I was on the fence but now I will vote to close this as a dupe. – Paulo Scardine Jan 29 '15 at 16:51
  • @PauloScardine I added the response directly from my program code and modified it a bit. Probably I got the solution from the same thread you posted but it was a long time ago. – Bogdan Goie Jan 29 '15 at 17:26