diff gpp/banners/admin.py @ 558:9a68fd3bd8a5

Creating a simple banner / ad campaign application, initially as a RFB / SG101 tie-in.
author Brian Neal <bgneal@gmail.com>
date Thu, 02 Feb 2012 18:56:48 -0600
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gpp/banners/admin.py	Thu Feb 02 18:56:48 2012 -0600
@@ -0,0 +1,34 @@
+"""
+This file contains the automatic admin site definitions for the banners models.
+
+"""
+from django.contrib import admin
+
+from banners.models import Campaign, Banner
+
+
+class BannerInline(admin.TabularInline):
+    model = Banner
+    extra = 1
+
+
+class CampaignAdmin(admin.ModelAdmin):
+    prepopulated_fields = {'slug': ['name']}
+    list_display = ['name', 'slug', 'creation_date']
+    date_hierarchy = 'creation_date'
+    search_fields = ['name']
+    inlines = [BannerInline]
+
+
+class BannerAdmin(admin.ModelAdmin):
+    list_display = ['campaign', 'description', 'image_tag', 'creation_date']
+    date_hierarchy = 'creation_date'
+    search_fields = ['description']
+    list_filter = ['campaign']
+
+    def image_tag(self, obj):
+        return '<img src="%s" alt="%s" />' % (obj.image.url, obj.description)
+    image_tag.allow_tags = True
+
+admin.site.register(Campaign, CampaignAdmin)
+admin.site.register(Banner, BannerAdmin)