mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-16 21:30:23 +00:00
Improved docs to include example on how to use plain ImageSpec (defined outside of model, not ImageSpecField) with AdminThumbnail.
This commit is contained in:
parent
5281859d60
commit
934a5283ad
1 changed files with 31 additions and 0 deletions
31
README.rst
31
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``.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue