1

I use ImageKit to display images inside Django Admin site and it works fine:

@admin.register(Client)
class ClientAdmin(admin.ModelAdmin):
    list_display = ['title', 'client_logo', ]

    client_logo = AdminThumbnail(image_field='logo')
    client_logo.short_description = 'Logo'

    readonly_fields = ['client_logo']

But I need to display the images as thumbnails not in the original dimension, but I can't figure out how to use processors there.

enter image description here

Omid Shojaee
  • 333
  • 1
  • 4
  • 20

1 Answers1

0

Based on the documentation (https://django-imagekit.readthedocs.io/en/latest/#admin), I think you can only use AdminThumbnail to refer to an existing model field.

Could you use ImageSpecField within your models.py to generate a smaller version of the logo (https://django-imagekit.readthedocs.io/en/latest/#defining-specs-in-models)?

logo_thumbnail = ImageSpecField(source='logo',
                                processors=[ResizeToFit(width=150)],
                                format='JPEG')

And then just change the reference in admin.py:

client_logo = AdminThumbnail(image_field='logo_thumbnail')

Otherwise, if you don't want to change your model, you'd probably need to manually overwrite the admin templates: https://docs.djangoproject.com/en/4.0/ref/contrib/admin/#overriding-admin-templates

Cmastris
  • 23
  • 6