gremmie@1: """ gremmie@1: This file contains the admin definitions for the POTD application. gremmie@1: """ bgneal@267: from django.contrib import admin bgneal@267: from django.conf import settings gremmie@1: gremmie@1: from potd.models import Photo gremmie@1: from potd.models import Current gremmie@1: from potd.models import Sequence gremmie@1: bgneal@267: bgneal@330: IMG_TAG = 'thumbnail' bgneal@330: bgneal@330: gremmie@1: class PhotoAdmin(admin.ModelAdmin): bgneal@535: fields = ['photo', 'caption', 'description', 'user', 'potd_count'] bgneal@535: raw_id_fields = ['user'] bgneal@535: list_display = ['__unicode__', 'thumbnail'] bgneal@535: actions = ['regen_thumbnail'] bgneal@535: search_fields = ['caption', 'description'] gremmie@1: bgneal@267: class Media: bgneal@267: js = settings.GPP_THIRD_PARTY_JS['tiny_mce'] bgneal@267: bgneal@330: def thumbnail(self, obj): bgneal@330: return IMG_TAG % obj.thumb.url bgneal@330: thumbnail.allow_tags = True bgneal@330: bgneal@330: def regen_thumbnail(self, request, qs): bgneal@330: """ bgneal@330: Regenerates the thumbnail for the selected photos. bgneal@330: """ bgneal@330: for photo in qs: bgneal@330: photo.generate_thumb() bgneal@330: photo.save() bgneal@330: bgneal@330: regen_thumbnail.short_description = "Regenerate thumbs for selected photos" bgneal@330: bgneal@330: gremmie@1: class CurrentAdmin(admin.ModelAdmin): bgneal@330: list_display = ('__unicode__', 'thumbnail') gremmie@1: raw_id_fields = ('potd', ) gremmie@1: bgneal@330: def thumbnail(self, obj): bgneal@330: return IMG_TAG % obj.potd.thumb.url bgneal@330: thumbnail.allow_tags = True bgneal@330: bgneal@330: gremmie@1: admin.site.register(Photo, PhotoAdmin) gremmie@1: admin.site.register(Current, CurrentAdmin) gremmie@1: admin.site.register(Sequence)