comparison gpp/downloads/admin.py @ 192:341759e1cda1

Implementing #67: use a denormalized count field on download categories to reduce database queries.
author Brian Neal <bgneal@gmail.com>
date Sat, 03 Apr 2010 01:10:00 +0000
parents d6f3c38e8f50
children b4305e18d3af
comparison
equal deleted inserted replaced
191:046e6ef0ff45 192:341759e1cda1
7 from downloads.models import Download 7 from downloads.models import Download
8 from downloads.models import Category 8 from downloads.models import Category
9 from downloads.models import AllowedExtension 9 from downloads.models import AllowedExtension
10 from downloads.models import VoteRecord 10 from downloads.models import VoteRecord
11 11
12
13 class CategoryAdmin(admin.ModelAdmin):
14 list_display = ('title', 'description', 'count')
15 readonly_fields = ('count', )
16
17
12 class DownloadAdmin(admin.ModelAdmin): 18 class DownloadAdmin(admin.ModelAdmin):
13 exclude = ('html', ) 19 exclude = ('html', )
14 list_display = ('title', 'user', 'category', 'date_added', 'ip_address', 20 list_display = ('title', 'user', 'category', 'date_added', 'ip_address',
15 'hits', 'average_score', 'size', 'is_public') 21 'hits', 'average_score', 'size', 'is_public')
16 list_filter = ('date_added', 'is_public', 'category', 'user', 'ip_address') 22 list_filter = ('date_added', 'is_public', 'category', 'user', 'ip_address')
17 date_hierarchy = 'date_added' 23 date_hierarchy = 'date_added'
18 ordering = ('-date_added', ) 24 ordering = ('-date_added', )
19 search_fields = ('title', 'description', 'user__username') 25 search_fields = ('title', 'description', 'user__username')
20 raw_id_fields = ('user', ) 26 raw_id_fields = ('user', )
21 save_on_top = True 27 save_on_top = True
22 28
23 29
24 class VoteRecordAdmin(admin.ModelAdmin): 30 class VoteRecordAdmin(admin.ModelAdmin):
25 list_display = ('user', 'download', 'vote_date') 31 list_display = ('user', 'download', 'vote_date')
26 list_filter = ('user', 'download') 32 list_filter = ('user', 'download')
27 date_hierarchy = 'vote_date' 33 date_hierarchy = 'vote_date'
28 34
29 35
30 admin.site.register(Download, DownloadAdmin) 36 admin.site.register(Download, DownloadAdmin)
31 admin.site.register(Category) 37 admin.site.register(Category, CategoryAdmin)
32 admin.site.register(AllowedExtension) 38 admin.site.register(AllowedExtension)
33 admin.site.register(VoteRecord, VoteRecordAdmin) 39 admin.site.register(VoteRecord, VoteRecordAdmin)
34 40
35 # vim: ts=4 sw=4