From 336220bd9841c47584b9ab67a2b6570bce73d1dc Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Fri, 5 May 2023 15:12:22 +0530 Subject: [PATCH] feat: return workspace and project details in estimate endpoints (#1009) --- apiserver/plane/api/serializers/estimate.py | 6 ++++++ apiserver/plane/api/views/estimate.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/apiserver/plane/api/serializers/estimate.py b/apiserver/plane/api/serializers/estimate.py index 360275562..3cb0e4713 100644 --- a/apiserver/plane/api/serializers/estimate.py +++ b/apiserver/plane/api/serializers/estimate.py @@ -2,9 +2,13 @@ from .base import BaseSerializer from plane.db.models import Estimate, EstimatePoint +from plane.api.serializers import WorkspaceLiteSerializer, ProjectLiteSerializer class EstimateSerializer(BaseSerializer): + workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace") + project_detail = ProjectLiteSerializer(read_only=True, source="project") + class Meta: model = Estimate fields = "__all__" @@ -27,6 +31,8 @@ class EstimatePointSerializer(BaseSerializer): class EstimateReadSerializer(BaseSerializer): points = EstimatePointSerializer(read_only=True, many=True) + workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace") + project_detail = ProjectLiteSerializer(read_only=True, source="project") class Meta: model = Estimate diff --git a/apiserver/plane/api/views/estimate.py b/apiserver/plane/api/views/estimate.py index e878ccafc..49c3ba2d0 100644 --- a/apiserver/plane/api/views/estimate.py +++ b/apiserver/plane/api/views/estimate.py @@ -53,7 +53,7 @@ class BulkEstimatePointEndpoint(BaseViewSet): try: estimates = Estimate.objects.filter( workspace__slug=slug, project_id=project_id - ).prefetch_related("points") + ).prefetch_related("points").select_related("workspace", "project") serializer = EstimateReadSerializer(estimates, many=True) return Response(serializer.data, status=status.HTTP_200_OK) except Exception as e: