comparison gpp/forums/admin.py @ 562:98b373ca09f3

For bitbucket issue #3, ensure that changes to Profile, Post & Topic models via the admin cause the search index to be updated.
author Brian Neal <bgneal@gmail.com>
date Wed, 08 Feb 2012 18:58:57 -0600
parents 9e42e6618168
children
comparison
equal deleted inserted replaced
561:8f3b7f0d4d13 562:98b373ca09f3
8 from forums.models import Topic 8 from forums.models import Topic
9 from forums.models import Post 9 from forums.models import Post
10 from forums.models import FlaggedPost 10 from forums.models import FlaggedPost
11 from forums.models import ForumLastVisit 11 from forums.models import ForumLastVisit
12 from forums.models import TopicLastVisit 12 from forums.models import TopicLastVisit
13 from forums.signals import (notify_new_topic, notify_updated_topic,
14 notify_new_post, notify_updated_post)
15
13 import bio.badges 16 import bio.badges
14 17
15 18
16 class CategoryAdmin(admin.ModelAdmin): 19 class CategoryAdmin(admin.ModelAdmin):
17 list_display = ('name', 'position', ) 20 list_display = ('name', 'position', )
36 search_fields = ('name', ) 39 search_fields = ('name', )
37 date_hierarchy = 'creation_date' 40 date_hierarchy = 'creation_date'
38 list_filter = ('creation_date', 'update_date', ) 41 list_filter = ('creation_date', 'update_date', )
39 save_on_top = True 42 save_on_top = True
40 43
44 # override save_model() to update the search index
45 def save_model(self, request, obj, form, change):
46 obj.save()
47
48 if change:
49 notify_updated_topic(obj)
50 else:
51 notify_new_topic(obj)
52
41 53
42 class PostAdmin(admin.ModelAdmin): 54 class PostAdmin(admin.ModelAdmin):
43 list_display = ('user', 'creation_date', 'update_date', 'user_ip', 'summary') 55 list_display = ('user', 'creation_date', 'update_date', 'user_ip', 'summary')
44 raw_id_fields = ('topic', 'user', ) 56 raw_id_fields = ('topic', 'user', )
45 exclude = ('html', ) 57 exclude = ('html', )
49 ordering = ('-creation_date', ) 61 ordering = ('-creation_date', )
50 save_on_top = True 62 save_on_top = True
51 63
52 def queryset(self, request): 64 def queryset(self, request):
53 return Post.objects.select_related('user') 65 return Post.objects.select_related('user')
66
67 # override save_model() to update the search index
68 def save_model(self, request, obj, form, change):
69 obj.save()
70
71 if change:
72 notify_updated_post(obj)
73 else:
74 notify_new_post(obj)
54 75
55 76
56 class FlaggedPostAdmin(admin.ModelAdmin): 77 class FlaggedPostAdmin(admin.ModelAdmin):
57 list_display = ['__unicode__', 'flag_date', 'get_post_url'] 78 list_display = ['__unicode__', 'flag_date', 'get_post_url']
58 actions = ['accept_flags'] 79 actions = ['accept_flags']