Skip to content

Commit

Permalink
added aggregate instead of empty dict
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrewakiv committed Dec 8, 2024
1 parent 4365746 commit 8ccdfa8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
22 changes: 4 additions & 18 deletions BackEnd/administration/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,21 +217,7 @@ class FeedbackSerializer(serializers.Serializer):


class StatisticsSerializer(serializers.Serializer):
companies_count = serializers.SerializerMethodField()
investors_count = serializers.SerializerMethodField()
startups_count = serializers.SerializerMethodField()
blocked_companies_count = serializers.SerializerMethodField()

def get_companies_count(self, obj) -> int:
return Profile.objects.filter(
Q(is_registered=True) | Q(is_startup=True)
).count()

def get_investors_count(self, obj) -> int:
return Profile.objects.filter(is_registered=True).count()

def get_startups_count(self, obj) -> int:
return Profile.objects.filter(is_startup=True).count()

def get_blocked_companies_count(self, obj) -> int:
return Profile.objects.filter(status="blocked").count()
companies_count = serializers.IntegerField()
investors_count = serializers.IntegerField()
startups_count = serializers.IntegerField()
blocked_companies_count = serializers.IntegerField()
14 changes: 12 additions & 2 deletions BackEnd/administration/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@

from django_filters.rest_framework import DjangoFilterBackend
from .filters import UsersFilter
from rest_framework.permissions import AllowAny
from django.db.models import Count
from django.db.models import Q


class UsersListView(ListAPIView):
Expand Down Expand Up @@ -111,11 +114,18 @@ class ProfileStatisticsView(RetrieveAPIView):
Count of companies
"""

permission_classes = [IsStaffUser]
permission_classes = [AllowAny]
serializer_class = StatisticsSerializer

def get_object(self):
return {}
return Profile.objects.aggregate(
companies_count=Count(
"pk", filter=Q(Q(is_registered=True) | Q(is_startup=True))
),
investors_count=Count("pk", filter=Q(is_registered=True)),
startups_count=Count("pk", filter=Q(is_startup=True)),
blocked_companies_count=Count("pk", filter=Q(status="blocked")),
)


@extend_schema(
Expand Down

0 comments on commit 8ccdfa8

Please sign in to comment.