comparison user_photos/admin.py @ 719:cc8de231df5a

User photos in admin now have link to full size image.
author Brian Neal <bgneal@gmail.com>
date Thu, 19 Sep 2013 18:57:47 -0500
parents d7a0aaabc06c
children e0e79451339d
comparison
equal deleted inserted replaced
718:bf5340705d0c 719:cc8de231df5a
1 """Admin definitions for the user_photos application.""" 1 """Admin definitions for the user_photos application."""
2 from django.contrib import admin 2 from django.contrib import admin
3 3
4 from user_photos.models import Photo 4 from user_photos.models import Photo
5 5
6 IMG_TAG = '<img src="%s" alt="thumbnail" />' 6 IMG_TAG = """<a href="{url}"><img src="{thumb_url}" alt="thumbnail" /></a>"""
7 7
8 class PhotoAdmin(admin.ModelAdmin): 8 class PhotoAdmin(admin.ModelAdmin):
9 date_hierarchy = 'upload_date' 9 date_hierarchy = 'upload_date'
10 ordering = ['-upload_date'] 10 ordering = ['-upload_date']
11 raw_id_fields = ['user'] 11 raw_id_fields = ['user']
12 search_fields = ['user__username', 'user__email'] 12 search_fields = ['user__username', 'user__email']
13 list_display = ['__unicode__', 'thumbnail'] 13 list_display = ['__unicode__', 'thumbnail']
14 14
15 def thumbnail(self, obj): 15 def thumbnail(self, obj):
16 return IMG_TAG % obj.thumb_url 16 return IMG_TAG.format(url=obj.url, thumb_url=obj.thumb_url)
17 thumbnail.allow_tags = True 17 thumbnail.allow_tags = True
18 18
19 admin.site.register(Photo, PhotoAdmin) 19 admin.site.register(Photo, PhotoAdmin)