diff --git a/api/launchpad/launchpad_views.py b/api/launchpad/launchpad_views.py index 27c759aa..a2bb72cb 100644 --- a/api/launchpad/launchpad_views.py +++ b/api/launchpad/launchpad_views.py @@ -5,6 +5,7 @@ When, Case, IntegerField, + CharField, F, OuterRef, Subquery, @@ -28,7 +29,6 @@ def get(self, request): user=OuterRef("id"), task__event="launchpad", appraiser_approved=True, - task__hashtag="#lp24-introduction", ) .annotate(total_karma=Sum("karma")) .values("total_karma") @@ -39,35 +39,21 @@ def get(self, request): karma_activity_log_user__appraiser_approved=True, karma_activity_log_user__task__hashtag="#lp24-introduction", ) - .prefetch_related( - Prefetch( - "user_organization_link_user__org", - queryset=Organization.objects.filter( - org_type__in=["College", "School", "Company"] - ) - .select_related("district", "district_zone_state_name") - .all(), - ) - ) .annotate( karma=Subquery(karma_subquery, output_field=IntegerField()), time_=Max("karma_activity_log_user__created_at"), - org=F("user_organization_link_user__org__title"), - district_name=F("district__name"), - state=F("district__zone__state__name"), ) - .values("full_name", "karma", "org", "district_name", "state", "time_") .order_by("-karma", "time_") ) paginated_queryset = CommonUtils.get_paginated_queryset( users, request, - ["karma", "org", "district_name", "state", "time_"], + ["karma", "org", "district", "state", "time_"], sort_fields={ "karma": "karma", "org": "org", - "district_name": "district_name", + "district": "district", "state": "state", "time_": "time_", }, diff --git a/api/launchpad/serializers.py b/api/launchpad/serializers.py index 243d0ecd..cd369f31 100644 --- a/api/launchpad/serializers.py +++ b/api/launchpad/serializers.py @@ -4,9 +4,9 @@ class LaunchpadLeaderBoardSerializer(serializers.ModelSerializer): karma = serializers.IntegerField() - org = serializers.CharField() - district_name = serializers.CharField() - state = serializers.CharField() + 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") class Meta: model = User