Django Rest filter and filerset_class not working in custom action method

I'm having issues getting the filterset_class work in my view's action method. When I filter the data in /api/measurement/aggregated_data everything works fine, but I need to use these filters in my action method as well, so I can download the results. Here's my

class AggregatedDataViewSet(ReadOnlyModelViewSet):
    serializer_class = AggregatedDataSerializer
    queryset = AggregatedData.objects.all()
    filter_backends = [DjangoFilterBackend, OrderingFilter, SearchFilter]
    filterset_class = AggregatedDataFilter
    search_fields = ['parameter__measurand__name', 'river_site__lawa_code']
    @action(detail=False, methods=['get'], url_path='download')
    def download(self, request, *args, **kwargs):
        qs = self.filterset_class(self.get_queryset())
        # rest of the code...

I apply filters in filterset_class in /api/measurement/aggregated_data and the url changes as well and will look something like this:

When I click the download action, qs returns all data, so the filters are not applied. I want these filters in the url to be applied to the download method as well, but somehow they are not recognized by it. What is going wrong here and what is the best way to do what I am expecting?

Back to Top