Source

gnocchi-gallery / gnocchi / gallery / admin.py

funkybob 80395db 





































from django.contrib import admin
from gnocchi.gallery import models
from easy_thumbnails.files import get_thumbnailer
from gnocchi.tools.admin import InlineAttributeAdmin

class ImageInline(admin.TabularInline):
    model = models.Image

class GalleryAdmin(admin.ModelAdmin):
    list_display = ('name', 'slug',)
    prepopulated_fields = {
        'slug': ('name',)
    }
    inlines = (
        ImageInline,
    )

admin.site.register(models.Gallery, GalleryAdmin)

class ImageAdmin(admin.ModelAdmin):
    list_display = ('thumb', 'gallery', 'image', 'name', 'order',)
    list_filter = ('gallery', 'order',)
    list_editable = ('order',)

    def thumb(self, obj):
        img = get_thumbnailer(obj.image).get_thumbnail({'size': (70, 70,)})
        return '<img src="%s" alt="" />' % (img.url,)
    thumb.short_description = 'Thumbnail'
    thumb.allow_tags = True

admin.site.register(models.Image, ImageAdmin)

class ThumbnailConfigAdmin(admin.ModelAdmin):
    list_display = ('name',)
    inlines = (
        InlineAttributeAdmin,
    )

admin.site.register(models.ThumbnailConfig, ThumbnailConfigAdmin)