diff 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
line wrap: on
line diff
--- a/gpp/forums/admin.py	Mon Feb 06 20:37:02 2012 -0600
+++ b/gpp/forums/admin.py	Wed Feb 08 18:58:57 2012 -0600
@@ -10,6 +10,9 @@
 from forums.models import FlaggedPost
 from forums.models import ForumLastVisit
 from forums.models import TopicLastVisit
+from forums.signals import (notify_new_topic, notify_updated_topic,
+        notify_new_post, notify_updated_post)
+
 import bio.badges
 
 
@@ -38,6 +41,15 @@
     list_filter = ('creation_date', 'update_date', )
     save_on_top = True
 
+    # override save_model() to update the search index 
+    def save_model(self, request, obj, form, change):
+        obj.save()
+
+        if change:
+            notify_updated_topic(obj)
+        else:
+            notify_new_topic(obj)
+
 
 class PostAdmin(admin.ModelAdmin):
     list_display = ('user', 'creation_date', 'update_date', 'user_ip', 'summary')
@@ -52,6 +64,15 @@
     def queryset(self, request):
         return Post.objects.select_related('user')
 
+    # override save_model() to update the search index 
+    def save_model(self, request, obj, form, change):
+        obj.save()
+
+        if change:
+            notify_updated_post(obj)
+        else:
+            notify_new_post(obj)
+
 
 class FlaggedPostAdmin(admin.ModelAdmin):
     list_display = ['__unicode__', 'flag_date', 'get_post_url']