diff --git a/paperwork/api.py b/paperwork/api.py index d66885a..6369170 100644 --- a/paperwork/api.py +++ b/paperwork/api.py @@ -28,7 +28,7 @@ class DepartmentViewSet(viewsets.ModelViewSet): Generate a mailing list for each department, containing all certified users for tools in that department or child departments """ - departments = self.queryset.filter(has_mailing_list=True).prefetch_related( + departments = self.queryset.prefetch_related( "children", "shop_lead_flag__members", Prefetch( @@ -37,7 +37,7 @@ class DepartmentViewSet(viewsets.ModelViewSet): ), ) lists = {} - for department in departments: + for department in departments.filter(has_mailing_list=True): if department.shop_lead_flag is not None: moderator_emails = { member.email for member in department.shop_lead_flag.members.all() @@ -75,12 +75,12 @@ class DepartmentViewSet(viewsets.ModelViewSet): "members" ] - for department in departments: + for department in departments.filter(has_mailing_list=True): if department.parent_id is None: recurse_children(department) shopleads = {} - for department in departments: + for department in departments.filter(shop_lead_flag__isnull=False): for member in department.shop_lead_flag.members.all(): if member not in shopleads: shopleads[member] = []