diff potd/admin.py @ 581:ee87ea74d46b

For Django 1.4, rearranged project structure for new manage.py.
author Brian Neal <bgneal@gmail.com>
date Sat, 05 May 2012 17:10:48 -0500
parents gpp/potd/admin.py@4021ea1045f7
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/potd/admin.py	Sat May 05 17:10:48 2012 -0500
@@ -0,0 +1,51 @@
+"""
+This file contains the admin definitions for the POTD application.
+"""
+from django.contrib import admin
+from django.conf import settings
+
+from potd.models import Photo
+from potd.models import Current
+from potd.models import Sequence
+
+
+IMG_TAG = '<img src="%s" alt="thumbnail" />'
+
+
+class PhotoAdmin(admin.ModelAdmin):
+    fields = ['photo', 'caption', 'description', 'user', 'potd_count']
+    raw_id_fields = ['user']
+    list_display = ['__unicode__', 'thumbnail']
+    actions = ['regen_thumbnail']
+    search_fields = ['caption', 'description']
+
+    class Media:
+        js = settings.GPP_THIRD_PARTY_JS['tiny_mce']
+
+    def thumbnail(self, obj):
+        return IMG_TAG % obj.thumb.url
+    thumbnail.allow_tags = True
+
+    def regen_thumbnail(self, request, qs):
+        """
+        Regenerates the thumbnail for the selected photos.
+        """
+        for photo in qs:
+            photo.generate_thumb()
+            photo.save()
+
+    regen_thumbnail.short_description = "Regenerate thumbs for selected photos"
+
+
+class CurrentAdmin(admin.ModelAdmin):
+    list_display = ('__unicode__', 'thumbnail')
+    raw_id_fields = ('potd', )
+
+    def thumbnail(self, obj):
+        return IMG_TAG % obj.potd.thumb.url
+    thumbnail.allow_tags = True
+
+
+admin.site.register(Photo, PhotoAdmin)
+admin.site.register(Current, CurrentAdmin)
+admin.site.register(Sequence)