gremmie@1: """This file contains the automatic admin site definitions for the weblinks models""" bgneal@204: import datetime gremmie@1: gremmie@1: from django.contrib import admin gremmie@1: from weblinks.models import Category bgneal@204: from weblinks.models import PendingLink gremmie@1: from weblinks.models import Link gremmie@1: from weblinks.models import FlaggedLink gremmie@1: bgneal@193: bgneal@193: class CategoryAdmin(admin.ModelAdmin): bgneal@242: list_display = ('title', 'slug', 'description', 'count') bgneal@242: prepopulated_fields = {'slug': ('title', )} bgneal@193: readonly_fields = ('count', ) bgneal@193: bgneal@193: bgneal@204: class PendingLinkAdmin(admin.ModelAdmin): bgneal@204: list_display = ('title', 'url', 'user', 'category', 'date_added') bgneal@204: raw_id_fields = ('user', ) bgneal@204: actions = ('approve_links', ) bgneal@277: readonly_fields = ('update_date', ) bgneal@204: bgneal@204: def approve_links(self, request, qs): bgneal@204: for pending_link in qs: bgneal@204: link = Link(category=pending_link.category, bgneal@204: title=pending_link.title, bgneal@204: url=pending_link.url, bgneal@204: description=pending_link.description, bgneal@204: user=pending_link.user, bgneal@204: date_added=datetime.datetime.now(), bgneal@204: hits=0, bgneal@204: is_public=True) bgneal@204: link.save() bgneal@204: pending_link.delete() bgneal@204: bgneal@204: approve_links.short_description = "Approve selected links" bgneal@204: bgneal@204: gremmie@1: class LinkAdmin(admin.ModelAdmin): gremmie@1: list_display = ('title', 'url', 'category', 'date_added', 'hits', 'is_public') gremmie@1: list_filter = ('date_added', 'is_public', 'category') gremmie@1: date_hierarchy = 'date_added' gremmie@1: ordering = ('-date_added', ) gremmie@1: search_fields = ('title', 'description', 'url', 'user__username') gremmie@1: raw_id_fields = ('user', ) bgneal@277: readonly_fields = ('update_date', ) gremmie@1: save_on_top = True gremmie@1: bgneal@193: gremmie@1: class FlaggedLinkAdmin(admin.ModelAdmin): bgneal@165: list_display = ('__unicode__', 'url', 'get_link_url', 'user', 'date_flagged') gremmie@1: date_hierarchy = 'date_flagged' gremmie@1: raw_id_fields = ('user', ) gremmie@1: bgneal@193: admin.site.register(Category, CategoryAdmin) bgneal@204: admin.site.register(PendingLink, PendingLinkAdmin) gremmie@1: admin.site.register(Link, LinkAdmin) gremmie@1: admin.site.register(FlaggedLink, FlaggedLinkAdmin)