Update AdminThumbnail

This commit is contained in:
Nyymix 2025-01-11 23:07:53 +02:00
parent 5e876571f8
commit 0c00bc20df

View file

@ -1,9 +1,24 @@
from django.contrib import admin from django.contrib import admin
from imagekit import ImageSpec
from imagekit.admin import AdminThumbnail from imagekit.admin import AdminThumbnail
from imagekit.cachefiles import ImageCacheFile
from imagekit.processors import ResizeToFill
from gallery.models import Album, City, Location, Photo from gallery.models import Album, City, Location, Photo
class AdminThumbnailSpec(ImageSpec):
processors = [ResizeToFill(50, 50)]
format = 'JPEG'
options = {'quality': 60}
def cached_admin_thumb(instance):
cached = ImageCacheFile(AdminThumbnailSpec(instance.photo))
cached.generate()
return cached
class CityAdmin(admin.ModelAdmin): class CityAdmin(admin.ModelAdmin):
list_display = ('name',) list_display = ('name',)
search_fields = ('name',) search_fields = ('name',)
@ -21,18 +36,18 @@ class LocationAdmin(admin.ModelAdmin):
class AlbumAdmin(admin.ModelAdmin): class AlbumAdmin(admin.ModelAdmin):
prepopulated_fields = {'slug': ('name',)} prepopulated_fields = {'slug': ('name',)}
list_display = ('__str__',) list_display = ('__str__', 'location', 'album_date', 'is_public', )
search_fields = ('name',) search_fields = ('name',)
ordering = ('name',) ordering = ('name',)
list_per_page = 30 list_per_page = 30
list_editable = ('is_public', 'location')
class PhotoAdmin(admin.ModelAdmin): class PhotoAdmin(admin.ModelAdmin):
list_display = ('__str__', 'album', 'admin_thumbnail',) list_display = ('slug', 'album', 'admin_thumbnail',)
list_display_links = ('__str__',) list_display_links = ('slug',)
list_editable = ('album',)
readonly_fields = ['slug', 'taken_at', 'height', 'width', 'exif', ] readonly_fields = ['slug', 'taken_at', 'height', 'width', 'exif', ]
admin_thumbnail = AdminThumbnail(image_field='photo_thumbnail',) admin_thumbnail = AdminThumbnail(image_field=cached_admin_thumb)
admin.site.register(City, CityAdmin) admin.site.register(City, CityAdmin)