From 9c4fcca6c160fae3d6ccc5c137d332243feed3f9 Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Thu, 30 Mar 2023 16:33:16 +0530 Subject: [PATCH] fix: ordering in queryset (#598) --- apiserver/plane/api/views/cycle.py | 2 +- apiserver/plane/api/views/module.py | 2 +- apiserver/plane/api/views/page.py | 10 +++++----- apiserver/plane/api/views/project.py | 2 +- apiserver/plane/api/views/view.py | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apiserver/plane/api/views/cycle.py b/apiserver/plane/api/views/cycle.py index 6f1eb1aa6..db208e5f6 100644 --- a/apiserver/plane/api/views/cycle.py +++ b/apiserver/plane/api/views/cycle.py @@ -94,7 +94,7 @@ class CycleViewSet(BaseViewSet): filter=Q(issue_cycle__issue__state__group="backlog"), ) ) - .order_by("name", "-is_favorite") + .order_by("-is_favorite", "name") .distinct() ) diff --git a/apiserver/plane/api/views/module.py b/apiserver/plane/api/views/module.py index f1d29db2c..3cdb54f70 100644 --- a/apiserver/plane/api/views/module.py +++ b/apiserver/plane/api/views/module.py @@ -104,7 +104,7 @@ class ModuleViewSet(BaseViewSet): filter=Q(issue_module__issue__state__group="backlog"), ) ) - .order_by("name", "-is_favorite") + .order_by("-is_favorite", "name") ) def create(self, request, slug, project_id): diff --git a/apiserver/plane/api/views/page.py b/apiserver/plane/api/views/page.py index 2945044e1..7b6ebea53 100644 --- a/apiserver/plane/api/views/page.py +++ b/apiserver/plane/api/views/page.py @@ -258,7 +258,7 @@ class RecentPagesEndpoint(BaseAPIView): .select_related("workspace") .select_related("owned_by") .prefetch_related("labels") - .order_by("-updated_by") + .order_by("-is_favorite", "-updated_by") ) yesterdays_pages = ( @@ -274,7 +274,7 @@ class RecentPagesEndpoint(BaseAPIView): .select_related("workspace") .select_related("owned_by") .prefetch_related("labels") - .order_by("-updated_by") + .order_by("-is_favorite", "-updated_by") ) earlier_this_week = ( @@ -294,7 +294,7 @@ class RecentPagesEndpoint(BaseAPIView): .select_related("workspace") .select_related("owned_by") .prefetch_related("labels") - .order_by("-updated_by") + .order_by("-is_favorite", "-updated_by") ) todays_pages_serializer = PageSerializer(todays_pages, many=True) yesterday_pages_serializer = PageSerializer(yesterdays_pages, many=True) @@ -378,7 +378,7 @@ class MyPagesEndpoint(BaseAPIView): .annotate(is_favorite=Exists(subquery)) .filter(Q(owned_by=self.request.user) | Q(access=0)) .filter(project__project_projectmember__member=request.user) - .order_by("name", "-is_favorite") + .order_by("-is_favorite", "name") ) serializer = PageSerializer(pages, many=True) return Response(serializer.data, status=status.HTTP_200_OK) @@ -415,7 +415,7 @@ class CreatedbyOtherPagesEndpoint(BaseAPIView): .select_related("owned_by") .prefetch_related("labels") .annotate(is_favorite=Exists(subquery)) - .order_by("name", "-is_favorite") + .order_by("-is_favorite", "name") ) serializer = PageSerializer(pages, many=True) return Response(serializer.data, status=status.HTTP_200_OK) diff --git a/apiserver/plane/api/views/project.py b/apiserver/plane/api/views/project.py index f592fd083..869bd15c9 100644 --- a/apiserver/plane/api/views/project.py +++ b/apiserver/plane/api/views/project.py @@ -91,7 +91,7 @@ class ProjectViewSet(BaseViewSet): projects = ( self.get_queryset() .annotate(is_favorite=Exists(subquery)) - .order_by("name", "-is_favorite") + .order_by("-is_favorite", "name") ) return Response(ProjectDetailSerializer(projects, many=True).data) except Exception as e: diff --git a/apiserver/plane/api/views/view.py b/apiserver/plane/api/views/view.py index 8c0c9267f..b4e300dcb 100644 --- a/apiserver/plane/api/views/view.py +++ b/apiserver/plane/api/views/view.py @@ -53,7 +53,7 @@ class IssueViewViewSet(BaseViewSet): .select_related("project") .select_related("workspace") .annotate(is_favorite=Exists(subquery)) - .order_by("name", "-is_favorite") + .order_by("-is_favorite", "name") .distinct() )