Commits

Anonymous committed d112d2c

Set prepopulated fields on Gallery admin
Removed prefix stripping
Added attribute inline for ThumbnailConfig

Comments (0)

Files changed (1)

gnocchi_gallery/admin.py

 from gnocchi_gallery import models
 import os
 from easy_thumbnails.files import get_thumbnailer
+from gnocchi_tools.admin import InlineAttributeAdmin
 from django.conf import settings
 
 class ImageInline(admin.TabularInline):
 
 class GalleryAdmin(admin.ModelAdmin):
     list_display = ('name',)
+    prepopulated_fields = {
+        'slug': ('name',)
+    }
     inlines = (
         ImageInline,
     )
     list_editable = ('order',)
 
     def thumb(self, obj):
-        fname = obj.image
-        # Strip media root from file path
-        if os.path.commonprefix([fname, settings.MEDIA_ROOT]) == settings.MEDIA_ROOT:
-            fname = fname[len(settings.MEDIA_ROOT):]
-        img = get_thumbnailer(fname).get_thumbnail({'size': (70, 70,)})
+        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
 
 class ThumbnailConfigAdmin(admin.ModelAdmin):
     list_display = ('name',)
+    inlines = (
+        InlineAttributeAdmin,
+    )
 
 admin.site.register(models.ThumbnailConfig, ThumbnailConfigAdmin)