mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-16 21:30:23 +00:00
Allow callables for AdminThumbnail image_field arg
This allows images from related models to be displayed. Closes #138.
This commit is contained in:
parent
70ab4a0cc0
commit
548fb65618
1 changed files with 8 additions and 5 deletions
|
|
@ -21,11 +21,14 @@ class AdminThumbnail(object):
|
|||
self.template = template
|
||||
|
||||
def __call__(self, obj):
|
||||
try:
|
||||
thumbnail = getattr(obj, self.image_field)
|
||||
except AttributeError:
|
||||
raise Exception('The property %s is not defined on %s.' % \
|
||||
(self.image_field, obj.__class__.__name__))
|
||||
if callable(self.image_field):
|
||||
thumbnail = self.image_field(obj)
|
||||
else:
|
||||
try:
|
||||
thumbnail = getattr(obj, self.image_field)
|
||||
except AttributeError:
|
||||
raise Exception('The property %s is not defined on %s.' % \
|
||||
(self.image_field, obj.__class__.__name__))
|
||||
|
||||
original_image = getattr(thumbnail, 'source_file', None) or thumbnail
|
||||
template = self.template or 'imagekit/admin/thumbnail.html'
|
||||
|
|
|
|||
Loading…
Reference in a new issue