feat: return workspace member count on user workspace endpoint (#162)

This commit is contained in:
pablohashescobar 2023-01-11 14:44:35 +05:30 committed by GitHub
parent ad929dfd7e
commit 6db3cf2b4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -12,6 +12,7 @@ from plane.db.models import Workspace, WorkspaceMember, Team, WorkspaceMemberInv
class WorkSpaceSerializer(BaseSerializer):
owner = UserLiteSerializer(read_only=True)
total_members = serializers.IntegerField(read_only=True)
class Meta:
model = Workspace

View File

@ -10,7 +10,7 @@ from django.utils import timezone
from django.core.exceptions import ValidationError
from django.core.validators import validate_email
from django.contrib.sites.shortcuts import get_current_site
from django.db.models import CharField
from django.db.models import CharField, Count
from django.db.models.functions import Cast
# Third party modules
@ -119,7 +119,8 @@ class UserWorkSpacesEndpoint(BaseAPIView):
workspace_member__member=request.user,
)
.select_related("owner")
)
).annotate(total_members=Count("workspace_member"))
serializer = WorkSpaceSerializer(self.filter_queryset(workspace), many=True)
return Response(serializer.data, status=status.HTTP_200_OK)