From f3c55b1e25fe5ea9a5ef33306850410c49b934c8 Mon Sep 17 00:00:00 2001 From: jelanmathewjames Date: Sat, 1 Jun 2024 23:07:03 +0530 Subject: [PATCH] Update launchpad leaderboard serializers --- api/launchpad/launchpad_views.py | 6 +++++- api/launchpad/serializers.py | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/api/launchpad/launchpad_views.py b/api/launchpad/launchpad_views.py index c7d0e74f..6cb8ac64 100644 --- a/api/launchpad/launchpad_views.py +++ b/api/launchpad/launchpad_views.py @@ -1,4 +1,5 @@ -from django.db.models import Q, Sum, Max, Prefetch +from django.db.models import Q, Sum, Max, Prefetch, F +from django.db.models.functions import Coalesce from rest_framework.views import APIView @@ -32,6 +33,9 @@ def get(self, request): karma_activity_log_user__appraiser_approved=True, ), ), + org=F("user_organization_link_user__org__title"), + district_name=F("user_organization_link_user__org__district__name"), + state=F("user_organization_link_user__org__district__zone__state__name"), time_=Max("karma_activity_log_user__created_at"), ) .order_by("-karma", "time_") diff --git a/api/launchpad/serializers.py b/api/launchpad/serializers.py index cd369f31..243d0ecd 100644 --- a/api/launchpad/serializers.py +++ b/api/launchpad/serializers.py @@ -4,9 +4,9 @@ class LaunchpadLeaderBoardSerializer(serializers.ModelSerializer): karma = serializers.IntegerField() - org = serializers.ReadOnlyField(source="user_organization_link_user.org.title") - district_name = serializers.ReadOnlyField(source="user_organization_link_user.org.district.name") - state = serializers.ReadOnlyField(source="user_organization_link_user.org.district.zone.state.name") + org = serializers.CharField() + district_name = serializers.CharField() + state = serializers.CharField() class Meta: model = User