Skip to content

Instantly share code, notes, and snippets.

@mhulse
Created September 18, 2011 21:23
Show Gist options
  • Select an option

  • Save mhulse/1225566 to your computer and use it in GitHub Desktop.

Select an option

Save mhulse/1225566 to your computer and use it in GitHub Desktop.
SORL (and description example) in Django's admin change list view...
# ...
from sorl.thumbnail import get_thumbnail
# ...
# http://stackoverflow.com/questions/1378447/question-about-admin-py-list-display
def _get_photo(obj):
if obj.photo: # 'photo' = model field name.
im = get_thumbnail(obj.photo, '60')
return u'<a href="http://%s.%s/%s"><img src="%s" width="60" alt="Thumbnail image" /></a>' % (obj.photo.storage.bucket, obj.photo.storage.connection.server, obj.photo.name, im.url)
else:
return u'(No photo)'
_get_photo.short_description = u'thumbnail'
_get_photo.allow_tags = True
def _get_description(obj):
if obj.description: # 'description' = model field name.
return obj.description
else:
return u'(No description)'
_get_description.short_description = u'description'
_get_description.allow_tags = True
# ...
list_display = ('title', 'parent', _get_photo, _get_description,)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment