I am trying to filter data using a decorator action on Django Rest Framework, it works perfect if I use the global queryset (get_queryset() function) but I need to use it in a separate function.
I am using django-filter to perform it. This is the code.
My view:
class ShippingAPI(viewsets.ModelViewSet):
serializer_class = ShippingSerializer
filter_backends = (DjangoFilterBackend,)
filter_fields = ('origin__department', 'destination__department', 'first_collection_date', 'last_collection_date', 'vehicle')
The override (action)
@action(detail=False, methods=['GET'])
def filter_shippings(self, request, **kwargs):
queryset = Shipping.objects.filter(status=2, orderStatus=0)
serializer = SearchShippingSerializer(queryset, many=True) #Yes, I am using another serializer, but it is solved,I use diferent if it is necesary
return Response(serializer.data)
After use my url 'api/filter_shipping/(all filters here)', this still return all the data without the filters I am requesting.
Thanks for your help