Mercurial > public > sg101
comparison gpp/potd/admin.py @ 330:3c951521e0ec
Fixing #152; POTD was saving thumbnail every night and making tons of thumbnail directories all over. Also added thumbnail images in the admin.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 24 Feb 2011 03:45:50 +0000 |
parents | ded03f2513e9 |
children | 4021ea1045f7 |
comparison
equal
deleted
inserted
replaced
329:000c006fee97 | 330:3c951521e0ec |
---|---|
7 from potd.models import Photo | 7 from potd.models import Photo |
8 from potd.models import Current | 8 from potd.models import Current |
9 from potd.models import Sequence | 9 from potd.models import Sequence |
10 | 10 |
11 | 11 |
12 IMG_TAG = '<img src="%s" alt="thumbnail" />' | |
13 | |
14 | |
12 class PhotoAdmin(admin.ModelAdmin): | 15 class PhotoAdmin(admin.ModelAdmin): |
13 exclude = ('thumb', ) | 16 fields = ('photo', 'caption', 'description', 'user', 'potd_count') |
14 raw_id_fields = ('user', ) | 17 raw_id_fields = ('user', ) |
18 list_display = ('__unicode__', 'thumbnail') | |
19 actions = ('regen_thumbnail', ) | |
15 | 20 |
16 class Media: | 21 class Media: |
17 js = settings.GPP_THIRD_PARTY_JS['tiny_mce'] | 22 js = settings.GPP_THIRD_PARTY_JS['tiny_mce'] |
18 | 23 |
24 def thumbnail(self, obj): | |
25 return IMG_TAG % obj.thumb.url | |
26 thumbnail.allow_tags = True | |
27 | |
28 def regen_thumbnail(self, request, qs): | |
29 """ | |
30 Regenerates the thumbnail for the selected photos. | |
31 """ | |
32 for photo in qs: | |
33 photo.generate_thumb() | |
34 photo.save() | |
35 | |
36 regen_thumbnail.short_description = "Regenerate thumbs for selected photos" | |
37 | |
38 | |
19 class CurrentAdmin(admin.ModelAdmin): | 39 class CurrentAdmin(admin.ModelAdmin): |
40 list_display = ('__unicode__', 'thumbnail') | |
20 raw_id_fields = ('potd', ) | 41 raw_id_fields = ('potd', ) |
42 | |
43 def thumbnail(self, obj): | |
44 return IMG_TAG % obj.potd.thumb.url | |
45 thumbnail.allow_tags = True | |
46 | |
21 | 47 |
22 admin.site.register(Photo, PhotoAdmin) | 48 admin.site.register(Photo, PhotoAdmin) |
23 admin.site.register(Current, CurrentAdmin) | 49 admin.site.register(Current, CurrentAdmin) |
24 admin.site.register(Sequence) | 50 admin.site.register(Sequence) |