From efb2631e9afb7046f358768a084ec1ab5ff78080 Mon Sep 17 00:00:00 2001 From: Bryan Date: Wed, 1 Jan 2014 21:21:16 -0500 Subject: [PATCH] This should allow cascading course deletion over notes, but might lose cache sync --- karmaworld/apps/notes/models.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/karmaworld/apps/notes/models.py b/karmaworld/apps/notes/models.py index 78539d7..550e65c 100644 --- a/karmaworld/apps/notes/models.py +++ b/karmaworld/apps/notes/models.py @@ -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): -- 2.25.1