[Django]-Django Rest Framework ordering isnt working

3👍

Change

queryset = self.get_queryset()

to

queryset = self.filter_queryset(self.get_queryset())

to apply filtering and/or ordering.


Here’s what DRF’s ListModelMixin looks like (for inspiration).

class ListModelMixin:
    """
    List a queryset.
    """
    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())

        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)

Leave a comment