school note counts now parse through departments
authorBryan Bonvallet <btbonval@gmail.com>
Fri, 9 Jan 2015 22:31:36 +0000 (17:31 -0500)
committerBryan Bonvallet <btbonval@gmail.com>
Fri, 9 Jan 2015 22:31:36 +0000 (17:31 -0500)
for #377

karmaworld/apps/courses/models.py

index 778d2b447b57b9c71818bee5c9a905d6817f7452..13b39d7241be6f25c457473cdcc20cead9add9c6 100644 (file)
@@ -92,10 +92,15 @@ class School(models.Model):
         """ Update the School.file_count by summing the
             contained course.file_count
         """
-        self.file_count = sum([course.file_count for course in self.course_set.all()])
+        # find all courses without a department
+        course_list = list(self.course_set.all())
+        # find all courses with a department
+        for department in self.department_set.all():
+            for course in department.course_set.all():
+                course_list.append(course)
+        self.file_count = sum([course.file_count for course in course_list])
         self.save()
 
-
 @register_channel_name('school_object_by_name')
 class SchoolLookup(AnonLookupChannel):
     """