[Answered ]-Filter pk that before url_path in ListApiView. Django

1๐Ÿ‘

โœ…

You need to override get_queryset method:

class CollectionVideoViewSet(ListAPIView):
    """ViewSet for operation with videos in collection"""
    permission_classes = (IsAuthenticated,)
    queryset = Video.objects.all()
    serializer_class = CollectionVideoSerializer

    def get_queryset(self):
        # Assuming your `Video` model has a many-to-one relation to `Collection`
        return self.queryset.filter(
            collection__pk=self.kwargs['pk']
        )

In order to make your view return a paginated result, i.e. count, next, previous, you need to define a pagination_class in your view:

from rest_framework.pagination import PageNumberPagination

class CollectionVideoViewSet(ListAPIView):
    pagination_class = PageNumberPagination

More about pagination in DRF

๐Ÿ‘คErsain

0๐Ÿ‘

Yep, override get_queryset method of ListAPIView

class TeamList(generics.ListAPIView):
    serializer_class = TeamSerializer

    def get_queryset(self, *args, **kwargs):
        sc = EmployeeSearchCriteria(email=self.kwargs["email"], role=Employee.VIEWER)
        return EmployeeCalculatorService().get_team_by_employee(sc)
๐Ÿ‘คevgenyorlov1

Leave a comment