Sé que esto es una respuesta bastante tarde, pero pensé que una aplicación más completa sería de utilidad para otros ...
Si no lo tiene ya con django-Filer, obtener easy_thumbnails pip install easy-thumbnails
.
# -*- coding: utf-8 -*-
from django.contrib import admin
from easy_thumbnails.files import get_thumbnailer
from models import Photo
class PhotoAdmin(admin.ModelAdmin):
list_display = ('_thumbnail', 'title',)
list_display_links = ('_thumbnail', 'title',) # This makes the icon clickable too
readonly_fields = ('_thumbnail',)
fields = ('title', 'photo',)
def _thumbnail(self, obj):
if obj.photo:
thumbnailer = get_thumbnailer(obj.photo)
thumb = thumbnailer.get_thumbnail({
'crop': True,
'size': (50, 50),
# Sharpen it up a little, since its so small...
'detail': True,
# Put other options here...
})
# Note: we get the actual width/height rather than
# hard-coding 50, 50, just to be DRYer
return u'<img src="%s" alt="thumbnail: %s" width="%d" height="%d"/>' % (thumb.url, obj.photo.name, thumb.width, thumb.height)
else:
return "[No Image]"
# Optional, Provide a nicer label in the display
_thumbnail.short_description = 'Thumbnail'
# Required, leaves the markup un-escaped
_thumbnail.allow_tags = True
admin.site.register(Photo, PhotoAdmin)
Gracias por aclararme, no pude encontrarlo en los documentos. – Andy
@Andy, si eso funciona para usted, haga clic en la marca de verificación debajo del puntaje que esta respuesta debe aceptar. –
No estoy seguro pero creo que la sintaxis correcta es con '{}', no '% s'. Entonces sería: 'format_html (u '', obj.admin_thumbnail.url)'. – Paolo