annotate potd/admin.py @ 1201:fe10aea76cbd tip

Add 2023 MP3 compilation links
author Brian Neal <bgneal@gmail.com>
date Sun, 24 Mar 2024 14:50:23 -0500
parents ee87ea74d46b
children
rev   line source
gremmie@1 1 """
gremmie@1 2 This file contains the admin definitions for the POTD application.
gremmie@1 3 """
bgneal@267 4 from django.contrib import admin
bgneal@267 5 from django.conf import settings
gremmie@1 6
gremmie@1 7 from potd.models import Photo
gremmie@1 8 from potd.models import Current
gremmie@1 9 from potd.models import Sequence
gremmie@1 10
bgneal@267 11
bgneal@330 12 IMG_TAG = '<img src="%s" alt="thumbnail" />'
bgneal@330 13
bgneal@330 14
gremmie@1 15 class PhotoAdmin(admin.ModelAdmin):
bgneal@535 16 fields = ['photo', 'caption', 'description', 'user', 'potd_count']
bgneal@535 17 raw_id_fields = ['user']
bgneal@535 18 list_display = ['__unicode__', 'thumbnail']
bgneal@535 19 actions = ['regen_thumbnail']
bgneal@535 20 search_fields = ['caption', 'description']
gremmie@1 21
bgneal@267 22 class Media:
bgneal@267 23 js = settings.GPP_THIRD_PARTY_JS['tiny_mce']
bgneal@267 24
bgneal@330 25 def thumbnail(self, obj):
bgneal@330 26 return IMG_TAG % obj.thumb.url
bgneal@330 27 thumbnail.allow_tags = True
bgneal@330 28
bgneal@330 29 def regen_thumbnail(self, request, qs):
bgneal@330 30 """
bgneal@330 31 Regenerates the thumbnail for the selected photos.
bgneal@330 32 """
bgneal@330 33 for photo in qs:
bgneal@330 34 photo.generate_thumb()
bgneal@330 35 photo.save()
bgneal@330 36
bgneal@330 37 regen_thumbnail.short_description = "Regenerate thumbs for selected photos"
bgneal@330 38
bgneal@330 39
gremmie@1 40 class CurrentAdmin(admin.ModelAdmin):
bgneal@330 41 list_display = ('__unicode__', 'thumbnail')
gremmie@1 42 raw_id_fields = ('potd', )
gremmie@1 43
bgneal@330 44 def thumbnail(self, obj):
bgneal@330 45 return IMG_TAG % obj.potd.thumb.url
bgneal@330 46 thumbnail.allow_tags = True
bgneal@330 47
bgneal@330 48
gremmie@1 49 admin.site.register(Photo, PhotoAdmin)
gremmie@1 50 admin.site.register(Current, CurrentAdmin)
gremmie@1 51 admin.site.register(Sequence)