diff --git a/scipost_django/organizations/models.py b/scipost_django/organizations/models.py index 85a17595b47a96c10464932418d0f3c87e6f9041..8dc4a6dfc6c2aa9f0cf8ece46308773a2e613ce6 100644 --- a/scipost_django/organizations/models.py +++ b/scipost_django/organizations/models.py @@ -206,9 +206,11 @@ class Organization(models.Model): Returns all Profiles of authors associated to this Organization. """ profile_id_list = [ - tbl.profile.id for tbl in self.publicationauthorstable_set.all() + tbl.profile.id for tbl in self.publicationauthorstable_set.all( + ).select_related("profile") ] - return Profile.objects.filter(id__in=profile_id_list).distinct() + return Profile.objects.filter(id__in=profile_id_list).distinct( + ).select_related("contributor") def fellowships(self, year=None): """ @@ -222,7 +224,7 @@ class Organization(models.Model): Q(date_from__isnull=True) | Q(date_from__year__lte=year), Q(date_until__isnull=True) | Q(date_until__year__gte=year), ) - profile_ids = [a.profile.id for a in affiliations] + profile_ids = [a.profile.id for a in affiliations.select_related("profile")] fellowships = Fellowship.objects.filter( contributor__profile__id__in=profile_ids ) diff --git a/scipost_django/organizations/views.py b/scipost_django/organizations/views.py index fe9208caf365e8106b51e9c081181c41e9fd0962..6670a4ae68f97e069ec8105d2deb4e5b714574a4 100644 --- a/scipost_django/organizations/views.py +++ b/scipost_django/organizations/views.py @@ -196,10 +196,12 @@ class OrganizationDetailView(DetailView): if not self.request.user.has_perm("scipost.can_manage_organizations"): queryset = queryset.exclude(orgtype=ORGTYPE_PRIVATE_BENEFACTOR) # return queryset - return queryset.prefetch_related( + return queryset.select_related("parent").prefetch_related( "children", "subsidy_set", + "contactperson_set", "contactrole_set", + "funder_set", "organizationevent_set", "pubfractions", )