Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22f02bb
commit 8bb9dc5
Showing
13 changed files
with
435 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,74 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.contrib import admin | ||
from adworks.models import * | ||
from adworks.models import (Client, Campaign, Dimension, | ||
Attribute, Banner, Version) | ||
|
||
|
||
def smart_truncate(content, length=100, suffix='...'): | ||
if len(str(content)) <= length: | ||
return content | ||
else: | ||
return content[:length].rsplit(' ', 1)[0]+suffix | ||
|
||
|
||
class ClientAdmin(admin.ModelAdmin): | ||
list_display = ('title', 'website', 'created_date') | ||
def campaign_count(self, instance): | ||
return instance.campaign_set.count() | ||
|
||
list_display = ('title', 'website', 'campaign_count') | ||
search_fields = ('title', 'about') | ||
prepopulated_fields = {'slug': ('title',)} | ||
fieldsets = [ | ||
(None, {'fields': ['title', 'slug', 'about', 'website', 'logo']}), | ||
] | ||
admin.site.register(Client, ClientAdmin) | ||
fields = ('title', 'slug', 'logo', 'website', 'about') | ||
|
||
|
||
class CampaignAdmin(admin.ModelAdmin): | ||
list_display = ('title', 'client', 'created_date') | ||
list_filter = ('client',) | ||
def banner_count(self, instance): | ||
return instance.banner_set.count() | ||
|
||
list_display = ('title', 'client', 'banner_count') | ||
list_filter = ('client__title',) | ||
search_fields = ('title', 'summary', 'client') | ||
prepopulated_fields = {'slug': ('title',)} | ||
fieldsets = [ | ||
(None, {'fields': ['client', 'title', 'slug', 'summary', 'mediaplan']}), | ||
] | ||
admin.site.register(Campaign, CampaignAdmin) | ||
fields = ('client', 'title', 'slug', 'summary', 'mediaplan') | ||
|
||
|
||
class VersionInline(admin.StackedInline): | ||
model=Version | ||
extra=1 | ||
|
||
|
||
class BannerAdmin(admin.ModelAdmin): | ||
list_display = ('size', 'campaign') | ||
list_filter = ('size', 'campaign') | ||
def version_count(self, instance): | ||
return instance.version_set.count() | ||
|
||
list_display = ('dimension', 'attribute', 'campaign', 'version_count') | ||
list_filter = ('dimension__width', 'dimension__height', | ||
'attribute__title', 'campaign__title', 'campaign__client__title') | ||
search_fields = ('description',) | ||
fieldsets = [ | ||
(None, {'fields': ['campaign', 'size', 'description']}), | ||
] | ||
fields = ('campaign', ('dimension', 'attribute'), 'description') | ||
inlines = [VersionInline,] | ||
|
||
admin.site.register(Banner, BannerAdmin) | ||
|
||
class SizeAdmin(admin.ModelAdmin): | ||
list_display = ('width', 'height', 'attribute') | ||
list_filter = ('attribute',) | ||
admin.site.register(Size, SizeAdmin) | ||
class AttributeAdmin(admin.ModelAdmin): | ||
def summary(self, instance): | ||
return smart_truncate(instance.description) | ||
|
||
list_display = ('title', 'summary') | ||
|
||
|
||
class DimensionAdmin(admin.ModelAdmin): | ||
def dimension(self, instance): | ||
return u'%sx%s px' % (instance.width, instance.height) | ||
|
||
def summary(self, instance): | ||
return smart_truncate(instance.description) | ||
|
||
list_display = ('dimension', 'summary') | ||
list_filter = ('width', 'height') | ||
|
||
|
||
admin.site.register(Client, ClientAdmin) | ||
admin.site.register(Campaign, CampaignAdmin) | ||
admin.site.register(Banner, BannerAdmin) | ||
admin.site.register(Dimension, DimensionAdmin) | ||
admin.site.register(Attribute, AttributeAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
[ | ||
{ | ||
"pk": 1, | ||
"model": "sites.site", | ||
"fields": | ||
{ | ||
"domain": "localhost:8000", | ||
"name": "Example Site" | ||
} | ||
}, | ||
{ | ||
"pk": 1, | ||
"model": "auth.user", | ||
"fields": | ||
{ | ||
"username": "admin", | ||
"first_name": "Admin", | ||
"last_name": "User", | ||
"is_active": true, | ||
"is_superuser": true, | ||
"is_staff": true, | ||
"last_login": "2012-01-01 00:00:00", | ||
"groups": [], | ||
"user_permissions": [], | ||
"password": "sha1$e467e$508942f1c9be858fd46dc976c2496ba133ba4122", | ||
"email": "admin@example.com", | ||
"date_joined": "2012-01-01 00:00:00" | ||
} | ||
}, | ||
{ | ||
"pk": 2, | ||
"model": "auth.user", | ||
"fields": | ||
{ | ||
"username": "test", | ||
"first_name": "Test", | ||
"last_name": "User", | ||
"is_active": true, | ||
"is_superuser": true, | ||
"is_staff": false, | ||
"last_login": "2012-01-01 00:00:00", | ||
"groups": [], | ||
"user_permissions": [], | ||
"password": "sha1$3cb32$046d34b6eee347cb4ce099b266f1b9b3d066553a", | ||
"email": "test@example.com", | ||
"date_joined": "2012-01-01 00:00:00" | ||
} | ||
}, | ||
{ | ||
"pk": 3, | ||
"model": "auth.user", | ||
"fields": | ||
{ | ||
"username": "demo", | ||
"first_name": "Demo", | ||
"last_name": "User", | ||
"is_active": true, | ||
"is_superuser": false, | ||
"is_staff": false, | ||
"last_login": "2012-01-01 00:00:00", | ||
"groups": [], | ||
"user_permissions": [], | ||
"password": "sha1$1e2d3$0fd3f38117e48024ad68058252c42e9b9d69ca43", | ||
"email": "demo@example.com", | ||
"date_joined": "2012-01-01 00:00:00" | ||
} | ||
}, | ||
{ | ||
"pk": 1, | ||
"model": "adworks.client", | ||
"fields": | ||
{ | ||
"title": "Acme Corp", | ||
"slug": "acme-corp", | ||
"token": "7c879ad6a7611d94b34c1911910257c9" | ||
} | ||
}, | ||
{ | ||
"pk": 1, | ||
"model": "adworks.campaign", | ||
"fields": | ||
{ | ||
"client": 1, | ||
"title": "Campaign 1", | ||
"slug": "campaign-1", | ||
"token": "8216b7b37bbeef046f576d2c076058c2" | ||
} | ||
}, | ||
{ | ||
"pk": 1, | ||
"model": "adworks.dimension", | ||
"fields": | ||
{ | ||
"width": 300, | ||
"height": 200 | ||
} | ||
}, | ||
{ | ||
"pk": 1, | ||
"model": "adworks.attribute", | ||
"fields": | ||
{ | ||
"title": "Normal" | ||
} | ||
}, | ||
{ | ||
"pk": 1, | ||
"model": "adworks.banner", | ||
"fields": | ||
{ | ||
"campaign": 1, | ||
"dimension": 1, | ||
"attribute": 1, | ||
"token": "6a42f69d58e6232d44aa73fce282ac1a" | ||
} | ||
}, | ||
{ | ||
"pk": 1, | ||
"model": "adworks.version", | ||
"fields": | ||
{ | ||
"banner": 1, | ||
"revision": 1, | ||
"created_date": "2012-01-01T00:00:00" | ||
} | ||
} | ||
] |
Oops, something went wrong.