diff --git a/cohort/views/cohort_result.py b/cohort/views/cohort_result.py index 5afe84a1..10206c99 100644 --- a/cohort/views/cohort_result.py +++ b/cohort/views/cohort_result.py @@ -55,7 +55,9 @@ class Meta: class CohortResultViewSet(NestedViewSetMixin, UserObjectsRestrictedViewSet): - queryset = CohortResult.objects.select_related('request_query_snapshot__request') + queryset = CohortResult.objects.select_related('dated_measure', + 'dated_measure_global', + 'request_query_snapshot__request') serializer_class = CohortResultSerializer http_method_names = ['get', 'post', 'patch', 'delete'] swagger_tags = ["Cohorts"] diff --git a/cohort/views/request.py b/cohort/views/request.py index 72884309..66a0e286 100644 --- a/cohort/views/request.py +++ b/cohort/views/request.py @@ -1,10 +1,11 @@ +from django.db.models.query import Prefetch from django.http import QueryDict from drf_spectacular.utils import extend_schema_view, extend_schema from rest_framework import status from rest_framework_extensions.mixins import NestedViewSetMixin from admin_cohort.tools.cache import cache_response -from cohort.models import Request +from cohort.models import Request, RequestQuerySnapshot as RQS from cohort.serializers import RequestSerializer, RequestCreateSerializer, RequestPatchSerializer from cohort.views.shared import UserObjectsRestrictedViewSet @@ -19,7 +20,8 @@ destroy=extend_schema(responses={status.HTTP_204_NO_CONTENT: None}) ) class RequestViewSet(NestedViewSetMixin, UserObjectsRestrictedViewSet): - queryset = Request.objects.all() + queryset = Request.objects.prefetch_related(Prefetch(lookup='query_snapshots', + queryset=RQS.objects.prefetch_related('cohort_results'))) serializer_class = RequestSerializer http_method_names = ["get", "post", "patch", "delete"] filterset_fields = ('favorite',