I have a Django view which extends generics.ListAPIView
. It works fine with get requests, however since the char limits of the URL, now I need to send the request via POST. It is the same request, the only thing I need to change is the method to POST.
My current code is pretty simple:
class MyClass(generics.ListAPIView):
serializer_class = MySerializer
paginate_by = 1
def get_queryset(self):
queryset = SomeClass.objects.all()
# do some filtering
How could I add POST support to this class?
Try this:
class MyClass(generics.ListAPIView):
serializer_class = MySerializer
paginate_by = 1
def get_queryset(self):
queryset = SomeClass.objects.all()
# do some filtering
def post(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With