I have a Django Rest Framework set up and I'd like to be able to send PATCH requests to it that update a specific field. I looked at some previous posts and incorporated the partial update code in my view:
class RequestViewSet(viewsets.ModelViewSet):
queryset = Request.objects.filter(done = False).order_by('-time')
serializer_class = RequestSerializer
paginate_by = None
def partial_update(self, request, *args, **kwargs):
kwargs['partial'] = True
return self.update(request, *args, **kwargs)
When I try to run curl requests using PATCH, though, the object doesn't get updated. Here's an example of curl I was using:
curl --data '{"request": "foo"}' -X PATCH http://127.0.0.1:8000/api/request/1/
In the terminal, it returns the original, unmodified object. Is there a different way to set up the Model ViewSet to accept partial updates via PATCH?
curl --request PATCH http://127.0.0.1:8000/api/request/1/?done=True, it returns the original object without changingdonetotrue. (I tried upper and lower case true, for what it's worth.)requesttofoo. And are you unable to add a--dataparameter to that curl command?curl --request PATCH http://127.0.0.1:8000/api/request/1/ --data '{"done": "True"}'