Mercurial > public > sg101
comparison banners/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/banners/admin.py@9a68fd3bd8a5 |
children |
comparison
equal
deleted
inserted
replaced
580:c525f3e0b5d0 | 581:ee87ea74d46b |
---|---|
1 """ | |
2 This file contains the automatic admin site definitions for the banners models. | |
3 | |
4 """ | |
5 from django.contrib import admin | |
6 | |
7 from banners.models import Campaign, Banner | |
8 | |
9 | |
10 class BannerInline(admin.TabularInline): | |
11 model = Banner | |
12 extra = 1 | |
13 | |
14 | |
15 class CampaignAdmin(admin.ModelAdmin): | |
16 prepopulated_fields = {'slug': ['name']} | |
17 list_display = ['name', 'slug', 'creation_date'] | |
18 date_hierarchy = 'creation_date' | |
19 search_fields = ['name'] | |
20 inlines = [BannerInline] | |
21 | |
22 | |
23 class BannerAdmin(admin.ModelAdmin): | |
24 list_display = ['campaign', 'description', 'image_tag', 'creation_date'] | |
25 date_hierarchy = 'creation_date' | |
26 search_fields = ['description'] | |
27 list_filter = ['campaign'] | |
28 | |
29 def image_tag(self, obj): | |
30 return '<img src="%s" alt="%s" />' % (obj.image.url, obj.description) | |
31 image_tag.allow_tags = True | |
32 | |
33 admin.site.register(Campaign, CampaignAdmin) | |
34 admin.site.register(Banner, BannerAdmin) |