django-imagekit icon indicating copy to clipboard operation
django-imagekit copied to clipboard

AdminThumbnail: source never exists for ImageSpecFields

Open DylanLukes opened this issue 11 years ago • 0 comments

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.

DylanLukes avatar Oct 02 '14 14:10 DylanLukes