Mercurial > public > sg101
comparison weblinks/admin.py @ 581:ee87ea74d46b
For Django 1.4, rearranged project structure for new manage.py.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 05 May 2012 17:10:48 -0500 |
parents | gpp/weblinks/admin.py@701730b2fcda |
children | 6e6492468bb8 |
comparison
equal
deleted
inserted
replaced
580:c525f3e0b5d0 | 581:ee87ea74d46b |
---|---|
1 """This file contains the automatic admin site definitions for the weblinks models""" | |
2 import datetime | |
3 | |
4 from django.contrib import admin | |
5 from weblinks.models import Category | |
6 from weblinks.models import PendingLink | |
7 from weblinks.models import Link | |
8 from weblinks.models import FlaggedLink | |
9 | |
10 | |
11 class CategoryAdmin(admin.ModelAdmin): | |
12 list_display = ('title', 'slug', 'description', 'count') | |
13 prepopulated_fields = {'slug': ('title', )} | |
14 readonly_fields = ('count', ) | |
15 | |
16 | |
17 class PendingLinkAdmin(admin.ModelAdmin): | |
18 list_display = ('title', 'url', 'user', 'category', 'date_added') | |
19 raw_id_fields = ('user', ) | |
20 actions = ('approve_links', ) | |
21 readonly_fields = ('update_date', ) | |
22 | |
23 def approve_links(self, request, qs): | |
24 for pending_link in qs: | |
25 link = Link(category=pending_link.category, | |
26 title=pending_link.title, | |
27 url=pending_link.url, | |
28 description=pending_link.description, | |
29 user=pending_link.user, | |
30 date_added=datetime.datetime.now(), | |
31 hits=0, | |
32 is_public=True) | |
33 link.save() | |
34 pending_link.delete() | |
35 | |
36 count = len(qs) | |
37 msg = "1 link" if count == 1 else "%d links" % count | |
38 self.message_user(request, "%s approved." % msg) | |
39 | |
40 approve_links.short_description = "Approve selected links" | |
41 | |
42 | |
43 class LinkAdmin(admin.ModelAdmin): | |
44 list_display = ('title', 'url', 'category', 'date_added', 'hits', 'is_public') | |
45 list_filter = ('date_added', 'is_public', 'category') | |
46 date_hierarchy = 'date_added' | |
47 ordering = ('-date_added', ) | |
48 search_fields = ('title', 'description', 'url', 'user__username') | |
49 raw_id_fields = ('user', ) | |
50 readonly_fields = ('update_date', ) | |
51 save_on_top = True | |
52 | |
53 | |
54 class FlaggedLinkAdmin(admin.ModelAdmin): | |
55 list_display = ('__unicode__', 'url', 'get_link_url', 'user', 'date_flagged') | |
56 date_hierarchy = 'date_flagged' | |
57 raw_id_fields = ('user', ) | |
58 | |
59 admin.site.register(Category, CategoryAdmin) | |
60 admin.site.register(PendingLink, PendingLinkAdmin) | |
61 admin.site.register(Link, LinkAdmin) | |
62 admin.site.register(FlaggedLink, FlaggedLinkAdmin) |