This should allow cascading course deletion over notes, but might lose cache sync
authorBryan <btbonval@gmail.com>
Thu, 2 Jan 2014 02:21:16 +0000 (21:21 -0500)
committerBryan <btbonval@gmail.com>
Thu, 2 Jan 2014 02:37:51 +0000 (21:37 -0500)
karmaworld/apps/notes/models.py

index 78539d76b61c411e6d6e81b1dc0e4eb941d8d3e1..550e65c1080a893bd735a795ab3519feaaa5f7f6 100644 (file)
@@ -219,8 +219,16 @@ class Note(Document):
 
 
 def update_note_counts(note_instance):
-    note_instance.course.update_note_count()
-    note_instance.course.school.update_note_count()
+    try:
+        # test if the course still exists, or if this is a cascade delete.
+        note_instance.course
+    except Couse.DoesNotExist:
+        # this is a cascade delete. there is no course to update
+        pass
+    else:
+        # course exists
+        note_instance.course.update_note_count()
+        note_instance.course.school.update_note_count()
 
 @receiver(post_save, sender=Note, weak=False)
 def note_save_receiver(sender, **kwargs):