From: Bryan Date: Thu, 2 Jan 2014 02:21:16 +0000 (-0500) Subject: This should allow cascading course deletion over notes, but might lose cache sync X-Git-Tag: release-20150131~341 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=efb2631e9afb7046f358768a084ec1ab5ff78080;p=oweals%2Fkarmaworld.git This should allow cascading course deletion over notes, but might lose cache sync --- 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):