diff --git a/apiserver/plane/api/serializers/project.py b/apiserver/plane/api/serializers/project.py index bf06b3fa2..0a8ad1cf8 100644 --- a/apiserver/plane/api/serializers/project.py +++ b/apiserver/plane/api/serializers/project.py @@ -82,6 +82,9 @@ class ProjectDetailSerializer(BaseSerializer): default_assignee = UserLiteSerializer(read_only=True) project_lead = UserLiteSerializer(read_only=True) is_favorite = serializers.BooleanField(read_only=True) + total_members = serializers.IntegerField(read_only=True) + total_cycles = serializers.IntegerField(read_only=True) + total_modules = serializers.IntegerField(read_only=True) class Meta: model = Project diff --git a/apiserver/plane/api/views/project.py b/apiserver/plane/api/views/project.py index 3851e31c1..e9b1520fe 100644 --- a/apiserver/plane/api/views/project.py +++ b/apiserver/plane/api/views/project.py @@ -5,7 +5,7 @@ from datetime import datetime # Django imports from django.core.exceptions import ValidationError from django.db import IntegrityError -from django.db.models import Q, Exists, OuterRef +from django.db.models import Q, Exists, OuterRef, Func, F from django.core.validators import validate_email from django.conf import settings @@ -46,6 +46,8 @@ from plane.db.models import ( ProjectMemberInvite, User, ProjectIdentifier, + Cycle, + Module, ) from plane.bgtasks.project_invitation_task import project_invitation @@ -92,6 +94,26 @@ class ProjectViewSet(BaseViewSet): self.get_queryset() .annotate(is_favorite=Exists(subquery)) .order_by("-is_favorite", "name") + .annotate( + total_members=ProjectMember.objects.filter( + project_id=OuterRef("id") + ) + .order_by() + .annotate(count=Func(F("id"), function="Count")) + .values("count") + ) + .annotate( + total_cycles=Cycle.objects.filter(project_id=OuterRef("id")) + .order_by() + .annotate(count=Func(F("id"), function="Count")) + .values("count") + ) + .annotate( + total_modules=Module.objects.filter(project_id=OuterRef("id")) + .order_by() + .annotate(count=Func(F("id"), function="Count")) + .values("count") + ) ) return Response(ProjectDetailSerializer(projects, many=True).data) except Exception as e: