Skip to content

Commit

Permalink
Fix ordering for User scratchlist (#1349)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkst committed Sep 23, 2024
1 parent fbc5278 commit 8b516a3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions backend/coreapp/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ..models.profile import Profile
from ..models.scratch import Scratch
from ..serializers import TerseScratchSerializer, serialize_profile
from .scratch import ScratchPagination
from .scratch import ScratchPagination, ScratchViewSet


class CurrentUser(APIView):
Expand Down Expand Up @@ -52,10 +52,10 @@ class CurrentUserScratchList(generics.ListAPIView): # type: ignore
pagination_class = ScratchPagination
serializer_class = TerseScratchSerializer
filter_backends = [filters.OrderingFilter]
ordering_fields = ["creation_time", "last_updated", "score"]
ordering_fields = ["creation_time", "last_updated", "score", "match_percent"]

def get_queryset(self) -> QuerySet[Scratch]:
return Scratch.objects.filter(owner=self.request.profile)
return ScratchViewSet.queryset.filter(owner=self.request.profile)


class UserScratchList(generics.ListAPIView): # type: ignore
Expand All @@ -70,10 +70,12 @@ class UserScratchList(generics.ListAPIView): # type: ignore
django_filters.rest_framework.DjangoFilterBackend,
filters.OrderingFilter,
]
ordering_fields = ["creation_time", "last_updated", "score"]
ordering_fields = ["creation_time", "last_updated", "score", "match_percent"]

def get_queryset(self) -> QuerySet[Scratch]:
return Scratch.objects.filter(owner__user__username=self.kwargs["username"])
return ScratchViewSet.queryset.filter(
owner__user__username=self.kwargs["username"]
)


@api_view(["GET"]) # type: ignore
Expand Down

0 comments on commit 8b516a3

Please sign in to comment.