From 934a5283ad823a5c637f875f07dcaf5eb617e2be Mon Sep 17 00:00:00 2001 From: mikob Date: Mon, 10 Apr 2017 17:46:29 +0900 Subject: [PATCH 1/2] Improved docs to include example on how to use plain ImageSpec (defined outside of model, not ImageSpecField) with AdminThumbnail. --- README.rst | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.rst b/README.rst index 84ec294..23d26ac 100644 --- a/README.rst +++ b/README.rst @@ -406,6 +406,37 @@ Django admin classes: admin.site.register(Photo, PhotoAdmin) +To use specs defined outside of models: + +.. code-block:: python + + from django.contrib import admin + from imagekit.admin import AdminThumbnail + from imagekit import ImageSpec + from imagekit.processors import ResizeToFill + from imagekit.cachefiles import ImageCacheFile + + from .models import Photo + + class AdminThumbnailSpec(ImageSpec): + processors = [ResizeToFill(100, 30)] + format = 'JPEG' + options = {'quality': 60 } + + def cached_admin_thumb(model): + # `image` is the name of the image field on the model + cached = ImageCacheFile(AdminThumbnailSpec(model.image)) + # only generates the first time, subsequent calls use cache + cached.generate() + return cached + + class PhotoAdmin(admin.ModelAdmin): + list_display = ('__str__', 'admin_thumbnail') + admin_thumbnail = AdminThumbnail(image_field=cached_admin_thumb) + + admin.site.register(Photo, PhotoAdmin) + + AdminThumbnail can even use a custom template. For more information, see ``imagekit.admin.AdminThumbnail``. From c24455ef36c36f0a844a98e692e60d6eaae15074 Mon Sep 17 00:00:00 2001 From: mikob Date: Wed, 10 May 2017 18:03:28 +0900 Subject: [PATCH 2/2] Update README.st change model->instance for clarity in defining specs outside of models. --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 23d26ac..7d40b05 100644 --- a/README.rst +++ b/README.rst @@ -423,9 +423,9 @@ To use specs defined outside of models: format = 'JPEG' options = {'quality': 60 } - def cached_admin_thumb(model): + def cached_admin_thumb(instance): # `image` is the name of the image field on the model - cached = ImageCacheFile(AdminThumbnailSpec(model.image)) + cached = ImageCacheFile(AdminThumbnailSpec(instance.image)) # only generates the first time, subsequent calls use cache cached.generate() return cached