location api: only prefetch location groups that are visible to the user

This commit is contained in:
Laura Klünder 2017-10-28 12:44:22 +02:00
parent 1536fb0e10
commit 4f0dce05a1

View file

@ -238,7 +238,7 @@ class LocationViewSet(RetrieveModelMixin, GenericViewSet):
queryset = queryset.filter(reduce(operator.or_, conditions))
# prefetch locationgroups
base_qs = LocationGroup.objects.all().select_related('category')
base_qs = LocationGroup.qs_for_request(self.request).select_related('category')
for model in get_submodels(SpecificLocation):
queryset = queryset.prefetch_related(Prefetch(model._meta.default_related_name + '__groups',
queryset=base_qs))