Wiem, że to dość późna odpowiedź, ale myślałem, że pełniejsza realizacja byłoby pomocne dla innych ...
Jeśli nie ma go już z django-filer, dostać 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)
Dziękuję za wyjaśnienia, nie mogłem znaleźć tego w dokumentach. – Andy
@Andy, jeśli to dla ciebie działa, kliknij znacznik wyboru pod partyturą, aby ta odpowiedź go zaakceptowała. –
Nie jestem pewien, ale uważam, że właściwą składnią jest '{}', a nie '% s'. Tak więc byłoby to: 'format_html (u '', obj.admin_thumbnail.url). – Paolo