From 406570ce8f0ba5cff68ba01af20dadf32a99f230 Mon Sep 17 00:00:00 2001 From: jelanmathewjames Date: Tue, 11 Jun 2024 14:45:42 +0530 Subject: [PATCH] fix rank anomaly --- api/launchpad/launchpad_views.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/api/launchpad/launchpad_views.py b/api/launchpad/launchpad_views.py index e709b4be..ab91cfd2 100644 --- a/api/launchpad/launchpad_views.py +++ b/api/launchpad/launchpad_views.py @@ -48,13 +48,15 @@ def get(self, request): 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"), - ).annotate( + ).order_by("-karma", "time_") + + users = users.annotate( rank=Window( expression=RowNumber(), - order_by=[F('karma').desc(), F('time_').asc()] + order_by=F("karma").desc(), ) - ).order_by("-karma", "time_") - + ).order_by("rank") + paginated_queryset = CommonUtils.get_paginated_queryset( users, request,