From 069ab1ea45c82c094bc50602310cbd564721055e Mon Sep 17 00:00:00 2001 From: Leander Schulten Date: Mon, 30 Sep 2024 01:30:00 +0200 Subject: [PATCH] AdminThumbnail: Use source from generator if image_field is a function --- imagekit/admin.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/imagekit/admin.py b/imagekit/admin.py index 9e171a97..0451b9f4 100644 --- a/imagekit/admin.py +++ b/imagekit/admin.py @@ -23,14 +23,19 @@ def __init__(self, image_field, template=None): def __call__(self, obj): if callable(self.image_field): thumbnail = self.image_field(obj) + generator = getattr(thumbnail, 'generator', None) + if generator: + original_image = getattr(generator, 'source', thumbnail) + else: + original_image = thumbnail else: try: thumbnail = getattr(obj, self.image_field) + original_image = getattr(thumbnail, 'source', None) or thumbnail 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, {