django-imagekit
django-imagekit copied to clipboard
AdminThumbnail: source never exists for ImageSpecFields
Given a simple model (as in the tutorial) with an ImageField and an ImageSpecField, the thumbnail shown in AdminThumbnail never links to the original image.
The issue is here in admin.py:
def __call__(self, obj):
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', None) or thumbnail
template = self.template or 'imagekit/admin/thumbnail.html'
return render_to_string(template, {
'model': obj,
'thumbnail': thumbnail,
'original_image': original_image,
})
When using an ImageSpecField, thumbnail is an ImageCacheFile. The source can be gotten, however it's in an ostensibly undocumented field: thumbnail.generator._source.