Skip to content

Instantly share code, notes, and snippets.

@somnathrakshit
Forked from armonge/admin.py
Created August 20, 2017 18:21
Show Gist options
  • Save somnathrakshit/24bd7becff3934b9e800915f3bf03f13 to your computer and use it in GitHub Desktop.
Save somnathrakshit/24bd7becff3934b9e800915f3bf03f13 to your computer and use it in GitHub Desktop.
Show an image in django admin list_display, using sorl-thumbnail
class ProductAdmin(admin.ModelAdmin):
list_display = ('name','thumb')
def thumb(self, obj):
return render_to_string('thumb.html',{
'image': obj.image
})
thumb.allow_tags = True
{% load thumbnail %}
{% thumbnail image '100x100' crop="top" as im %}
<img src="{{ im.url }}" alt="">
{% endthumbnail %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment