fix: ordering in queryset (#598)

This commit is contained in:
pablohashescobar 2023-03-30 16:33:16 +05:30 committed by GitHub
parent 5aad20e7ed
commit 9c4fcca6c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 9 deletions

View File

@ -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()
)

View File

@ -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):

View File

@ -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)

View File

@ -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:

View File

@ -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()
)