Commits

Anonymous committed 4cc84b9

added a thumbnail in the admin

  • Participants
  • Parent commits 414bc4b

Comments (0)

Files changed (3)

src/photos/admin.py

 from django.contrib import admin
 from photos.models import Photo, Album
 from django.utils.translation import ugettext as _
+from django.template.loader import get_template
+from django.template import Context
 
 class BaseAdmin():
     def queryset(self, request):
 
 class PhotoAdmin(admin.ModelAdmin, BaseAdmin):
     list_filter = ('display', 'timestamp_created', )
+    list_display = ('name', 'display', 'timestamp_created', 'get_thumbnail', )
     date_hierarchy = 'timestamp_created'
     description = _('Manage your uploaded photos.')
+    
+    def get_thumbnail(self, obj):
+        template = get_template('admin_thumbnail.html')
+        context = Context({'photo': obj})
+        return template.render(context)
+    
+    get_thumbnail.allow_tags = True
+    get_thumbnail.short_description = _('Thumbnail')
 
 admin.site.register(Photo, PhotoAdmin)
 

src/photos/templates/photos/admin_thumbnail.html

+{% load thumbnail %}
+<img src="{% thumbnail photo.photo 100x100 crop quality=50 %}" />

src/photos/tests/tests.py

 from django.contrib.auth.models import User
 from photos.models import Photo, Album
 
+class TemplateTagTest(TestCase):
+    pass
+
 class ViewTest(TestCase):
     def setUp(self):
         user, created = User.objects.get_or_create(username='anna')