From 136f28672fbdcd71274827bdd33bfe169c8da68f Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Mon, 9 Jun 2025 16:44:49 +0330 Subject: [PATCH] fix order_by of user relations --- apps/authorization/api/v1/api.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/authorization/api/v1/api.py b/apps/authorization/api/v1/api.py index 6a125e1..dc07080 100644 --- a/apps/authorization/api/v1/api.py +++ b/apps/authorization/api/v1/api.py @@ -1,5 +1,6 @@ from rest_framework_simplejwt.authentication import JWTAuthentication from rest_framework.permissions import AllowAny, IsAuthenticated +from apps.core.pagination import CustomPageNumberPagination from apps.core.exceptions import ConflictException from rest_framework.exceptions import APIException from apps.authorization.api.v1.serializers import ( @@ -81,3 +82,14 @@ class UserRelationViewSet(viewsets.ModelViewSet): queryset = UserRelations.objects.all() serializer_class = UserRelationSerializer + + def list(self, request, *args, **kwargs): + queryset = self.filter_queryset(self.get_queryset().order_by('-create_date')) + + page = self.paginate_queryset(queryset) + if page is not None: + serializer = self.get_serializer(page, many=True) + return self.get_paginated_response(serializer.data) + + serializer = self.get_serializer(queryset, many=True) + return Response(serializer.data)