diff gpp/weblinks/admin.py @ 193:fa7d82bfb100

Implement #68: add a denormalized count field to weblinks Category model to reduce database queries.
author Brian Neal <bgneal@gmail.com>
date Sat, 03 Apr 2010 02:15:04 +0000
parents 952e05cb3d80
children b4305e18d3af
line wrap: on
line diff
--- a/gpp/weblinks/admin.py	Sat Apr 03 01:10:00 2010 +0000
+++ b/gpp/weblinks/admin.py	Sat Apr 03 02:15:04 2010 +0000
@@ -5,6 +5,12 @@
 from weblinks.models import Link
 from weblinks.models import FlaggedLink
 
+
+class CategoryAdmin(admin.ModelAdmin):
+    list_display = ('title', 'description', 'count')
+    readonly_fields = ('count', )
+
+
 class LinkAdmin(admin.ModelAdmin):
     list_display = ('title', 'url', 'category', 'date_added', 'hits', 'is_public')
     list_filter = ('date_added', 'is_public', 'category')
@@ -14,11 +20,12 @@
     raw_id_fields = ('user', )
     save_on_top = True
 
+
 class FlaggedLinkAdmin(admin.ModelAdmin):
     list_display = ('__unicode__', 'url', 'get_link_url', 'user', 'date_flagged')
     date_hierarchy = 'date_flagged'
     raw_id_fields = ('user', )
 
-admin.site.register(Category)
+admin.site.register(Category, CategoryAdmin)
 admin.site.register(Link, LinkAdmin)
 admin.site.register(FlaggedLink, FlaggedLinkAdmin)