comparison news/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/news/admin.py@7854d75427af
children 6dba56996a21
comparison
equal deleted inserted replaced
580:c525f3e0b5d0 581:ee87ea74d46b
1 """
2 This file contains the automatic admin site definitions for the News models.
3 """
4 import datetime
5
6 from django.contrib import admin
7 from django.conf import settings
8
9 from news.models import PendingStory
10 from news.models import Story
11 from news.models import Category
12
13
14 class CategoryAdmin(admin.ModelAdmin):
15 prepopulated_fields = {'slug': ("title", )}
16 list_display = ('title', 'slug')
17
18
19 class PendingStoryAdmin(admin.ModelAdmin):
20 list_display = ('title', 'date_submitted', 'submitter')
21 list_filter = ('date_submitted', )
22 search_fields = ('title', 'short_text', 'long_text')
23 date_hierarchy = 'date_submitted'
24 actions = ('approve_story', )
25 readonly_fields = ('update_date', )
26 raw_id_fields = ('submitter', )
27
28 def approve_story(self, request, qs):
29 for pending_story in qs:
30 story = Story(
31 title=pending_story.title,
32 submitter=pending_story.submitter,
33 category=pending_story.category,
34 short_text=pending_story.short_text,
35 long_text=pending_story.long_text,
36 date_submitted=pending_story.date_submitted,
37 allow_comments=pending_story.allow_comments,
38 tags=pending_story.tags,
39 front_page_expiration=pending_story.front_page_expiration,
40 priority=pending_story.priority,
41 meta_description=pending_story.meta_description)
42 story.save()
43 pending_story.delete()
44
45 count = len(qs)
46 msg = "1 story" if count == 1 else "%d stories" % count
47 self.message_user(request, "%s approved." % msg)
48
49 approve_story.short_description = "Approve selected pending stories"
50
51 class Media:
52 js = ['js/news_admin.js'] + settings.GPP_THIRD_PARTY_JS['tiny_mce']
53
54
55 class StoryAdmin(admin.ModelAdmin):
56 list_display = ('title', 'date_submitted', 'submitter', 'category')
57 list_filter = ('date_submitted', 'category')
58 search_fields = ('title', 'short_text', 'long_text')
59 date_hierarchy = 'date_submitted'
60 readonly_fields = ('update_date', )
61 raw_id_fields = ('submitter', )
62
63 class Media:
64 js = ['js/news_admin.js'] + settings.GPP_THIRD_PARTY_JS['tiny_mce']
65
66
67 admin.site.register(Category, CategoryAdmin)
68 admin.site.register(Story, StoryAdmin)
69 admin.site.register(PendingStory, PendingStoryAdmin)