Commits

Anonymous committed f4d2e07

Add support for grappelli

Comments (0)

Files changed (1)

gnocchi/gallery/admin.py

+
 from django.contrib import admin
+from django import forms
+
 from gnocchi.gallery import models
+from gnocchi.tools.admin import InlineAttributeAdmin
+
 from easy_thumbnails.files import get_thumbnailer
-from gnocchi.tools.admin import InlineAttributeAdmin
+
+try:
+    import grappelli
+    HAS_GRAPPELLI = True
+except ImportError:
+    HAS_GRAPPELLI = False
 
 class ImageInline(admin.TabularInline):
     model = models.Image
     readonly_fields = ('width', 'height',)
 
+    if HAS_GRAPPELLI:
+        sortable_field_name = 'order'
+        formfield_overrides = {
+            models.PositiveIntegerField: { 'widget': forms.HiddenInput }
+        }
+
+
 class GalleryAdmin(admin.ModelAdmin):
     list_display = ('name', 'slug',)
     prepopulated_fields = {
 
     def thumb(self, obj):
         img = get_thumbnailer(obj.image).get_thumbnail({'size': (70, 70,)})
-        return '<img src="%s" alt="" />' % (img.url,)
+        return '<img src="%s" alt="">' % (img.url,)
     thumb.short_description = 'Thumbnail'
     thumb.allow_tags = True