annotate gpp/weblinks/admin.py @ 206:272d3a8c98e8

Some minor tweaks made while rebuilding the development database after Ubuntu 10.04 install.
author Brian Neal <bgneal@gmail.com>
date Mon, 03 May 2010 02:49:31 +0000
parents b4305e18d3af
children 7e8d2dda99e3
rev   line source
gremmie@1 1 """This file contains the automatic admin site definitions for the weblinks models"""
bgneal@204 2 import datetime
gremmie@1 3
gremmie@1 4 from django.contrib import admin
gremmie@1 5 from weblinks.models import Category
bgneal@204 6 from weblinks.models import PendingLink
gremmie@1 7 from weblinks.models import Link
gremmie@1 8 from weblinks.models import FlaggedLink
gremmie@1 9
bgneal@193 10
bgneal@193 11 class CategoryAdmin(admin.ModelAdmin):
bgneal@193 12 list_display = ('title', 'description', 'count')
bgneal@193 13 readonly_fields = ('count', )
bgneal@193 14
bgneal@193 15
bgneal@204 16 class PendingLinkAdmin(admin.ModelAdmin):
bgneal@204 17 list_display = ('title', 'url', 'user', 'category', 'date_added')
bgneal@204 18 raw_id_fields = ('user', )
bgneal@204 19 actions = ('approve_links', )
bgneal@204 20
bgneal@204 21 def approve_links(self, request, qs):
bgneal@204 22 for pending_link in qs:
bgneal@204 23 link = Link(category=pending_link.category,
bgneal@204 24 title=pending_link.title,
bgneal@204 25 url=pending_link.url,
bgneal@204 26 description=pending_link.description,
bgneal@204 27 user=pending_link.user,
bgneal@204 28 date_added=datetime.datetime.now(),
bgneal@204 29 hits=0,
bgneal@204 30 is_public=True)
bgneal@204 31 link.save()
bgneal@204 32 pending_link.delete()
bgneal@204 33
bgneal@204 34 approve_links.short_description = "Approve selected links"
bgneal@204 35
bgneal@204 36
gremmie@1 37 class LinkAdmin(admin.ModelAdmin):
gremmie@1 38 list_display = ('title', 'url', 'category', 'date_added', 'hits', 'is_public')
gremmie@1 39 list_filter = ('date_added', 'is_public', 'category')
gremmie@1 40 date_hierarchy = 'date_added'
gremmie@1 41 ordering = ('-date_added', )
gremmie@1 42 search_fields = ('title', 'description', 'url', 'user__username')
gremmie@1 43 raw_id_fields = ('user', )
gremmie@1 44 save_on_top = True
gremmie@1 45
bgneal@193 46
gremmie@1 47 class FlaggedLinkAdmin(admin.ModelAdmin):
bgneal@165 48 list_display = ('__unicode__', 'url', 'get_link_url', 'user', 'date_flagged')
gremmie@1 49 date_hierarchy = 'date_flagged'
gremmie@1 50 raw_id_fields = ('user', )
gremmie@1 51
bgneal@193 52 admin.site.register(Category, CategoryAdmin)
bgneal@204 53 admin.site.register(PendingLink, PendingLinkAdmin)
gremmie@1 54 admin.site.register(Link, LinkAdmin)
gremmie@1 55 admin.site.register(FlaggedLink, FlaggedLinkAdmin)