diff 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
line wrap: on
line diff
--- a/gpp/downloads/admin.py	Thu Apr 01 02:01:33 2010 +0000
+++ b/gpp/downloads/admin.py	Sat Apr 03 01:10:00 2010 +0000
@@ -9,27 +9,32 @@
 from downloads.models import AllowedExtension
 from downloads.models import VoteRecord
 
+
+class CategoryAdmin(admin.ModelAdmin):
+    list_display = ('title', 'description', 'count')
+    readonly_fields = ('count', )
+
+
 class DownloadAdmin(admin.ModelAdmin):
-     exclude = ('html', )
-     list_display = ('title', 'user', 'category', 'date_added', 'ip_address',
-                'hits', 'average_score', 'size', 'is_public')
-     list_filter = ('date_added', 'is_public', 'category', 'user', 'ip_address')
-     date_hierarchy = 'date_added'
-     ordering = ('-date_added', )
-     search_fields = ('title', 'description', 'user__username')
-     raw_id_fields = ('user', )
-     save_on_top = True
+    exclude = ('html', )
+    list_display = ('title', 'user', 'category', 'date_added', 'ip_address',
+               'hits', 'average_score', 'size', 'is_public')
+    list_filter = ('date_added', 'is_public', 'category', 'user', 'ip_address')
+    date_hierarchy = 'date_added'
+    ordering = ('-date_added', )
+    search_fields = ('title', 'description', 'user__username')
+    raw_id_fields = ('user', )
+    save_on_top = True
 
 
 class VoteRecordAdmin(admin.ModelAdmin):
-     list_display = ('user', 'download', 'vote_date')
-     list_filter = ('user', 'download')
-     date_hierarchy = 'vote_date'
+    list_display = ('user', 'download', 'vote_date')
+    list_filter = ('user', 'download')
+    date_hierarchy = 'vote_date'
 
 
 admin.site.register(Download, DownloadAdmin)
-admin.site.register(Category)
+admin.site.register(Category, CategoryAdmin)
 admin.site.register(AllowedExtension)
 admin.site.register(VoteRecord, VoteRecordAdmin)
 
-# vim: ts=4 sw=4