Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
580:c525f3e0b5d0 | 581:ee87ea74d46b |
---|---|
1 """ | |
2 This file contains the admin definitions for the POTD application. | |
3 """ | |
4 from django.contrib import admin | |
5 from django.conf import settings | |
6 | |
7 from potd.models import Photo | |
8 from potd.models import Current | |
9 from potd.models import Sequence | |
10 | |
11 | |
12 IMG_TAG = '<img src="%s" alt="thumbnail" />' | |
13 | |
14 | |
15 class PhotoAdmin(admin.ModelAdmin): | |
16 fields = ['photo', 'caption', 'description', 'user', 'potd_count'] | |
17 raw_id_fields = ['user'] | |
18 list_display = ['__unicode__', 'thumbnail'] | |
19 actions = ['regen_thumbnail'] | |
20 search_fields = ['caption', 'description'] | |
21 | |
22 class Media: | |
23 js = settings.GPP_THIRD_PARTY_JS['tiny_mce'] | |
24 | |
25 def thumbnail(self, obj): | |
26 return IMG_TAG % obj.thumb.url | |
27 thumbnail.allow_tags = True | |
28 | |
29 def regen_thumbnail(self, request, qs): | |
30 """ | |
31 Regenerates the thumbnail for the selected photos. | |
32 """ | |
33 for photo in qs: | |
34 photo.generate_thumb() | |
35 photo.save() | |
36 | |
37 regen_thumbnail.short_description = "Regenerate thumbs for selected photos" | |
38 | |
39 | |
40 class CurrentAdmin(admin.ModelAdmin): | |
41 list_display = ('__unicode__', 'thumbnail') | |
42 raw_id_fields = ('potd', ) | |
43 | |
44 def thumbnail(self, obj): | |
45 return IMG_TAG % obj.potd.thumb.url | |
46 thumbnail.allow_tags = True | |
47 | |
48 | |
49 admin.site.register(Photo, PhotoAdmin) | |
50 admin.site.register(Current, CurrentAdmin) | |
51 admin.site.register(Sequence) |