Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
192:341759e1cda1 | 193:fa7d82bfb100 |
---|---|
2 | 2 |
3 from django.contrib import admin | 3 from django.contrib import admin |
4 from weblinks.models import Category | 4 from weblinks.models import Category |
5 from weblinks.models import Link | 5 from weblinks.models import Link |
6 from weblinks.models import FlaggedLink | 6 from weblinks.models import FlaggedLink |
7 | |
8 | |
9 class CategoryAdmin(admin.ModelAdmin): | |
10 list_display = ('title', 'description', 'count') | |
11 readonly_fields = ('count', ) | |
12 | |
7 | 13 |
8 class LinkAdmin(admin.ModelAdmin): | 14 class LinkAdmin(admin.ModelAdmin): |
9 list_display = ('title', 'url', 'category', 'date_added', 'hits', 'is_public') | 15 list_display = ('title', 'url', 'category', 'date_added', 'hits', 'is_public') |
10 list_filter = ('date_added', 'is_public', 'category') | 16 list_filter = ('date_added', 'is_public', 'category') |
11 date_hierarchy = 'date_added' | 17 date_hierarchy = 'date_added' |
12 ordering = ('-date_added', ) | 18 ordering = ('-date_added', ) |
13 search_fields = ('title', 'description', 'url', 'user__username') | 19 search_fields = ('title', 'description', 'url', 'user__username') |
14 raw_id_fields = ('user', ) | 20 raw_id_fields = ('user', ) |
15 save_on_top = True | 21 save_on_top = True |
16 | 22 |
23 | |
17 class FlaggedLinkAdmin(admin.ModelAdmin): | 24 class FlaggedLinkAdmin(admin.ModelAdmin): |
18 list_display = ('__unicode__', 'url', 'get_link_url', 'user', 'date_flagged') | 25 list_display = ('__unicode__', 'url', 'get_link_url', 'user', 'date_flagged') |
19 date_hierarchy = 'date_flagged' | 26 date_hierarchy = 'date_flagged' |
20 raw_id_fields = ('user', ) | 27 raw_id_fields = ('user', ) |
21 | 28 |
22 admin.site.register(Category) | 29 admin.site.register(Category, CategoryAdmin) |
23 admin.site.register(Link, LinkAdmin) | 30 admin.site.register(Link, LinkAdmin) |
24 admin.site.register(FlaggedLink, FlaggedLinkAdmin) | 31 admin.site.register(FlaggedLink, FlaggedLinkAdmin) |