Search code examples
vue.jsdjango-rest-frameworkdjango-rest-viewsets

DRF PATCH method, got all values at type of string in request.data


I am sending axios.patch request with form-data in vue

axios.patch(`${API_BASE}/products/${id}/`, data, {
  headers: { 'Content-Type': 'multipart/form-data'
}

and calling Django ModelViewset partial update

    class MyViewSet(viewsets.ModelViewSet):
        def update(self, request, *args, **kwargs):
            data = request.data.copy()
            question = self.get_object()
            ...

the problem is that I am getting all values in stringified form.. null values as 'null', integer values as '1', and so on. enter image description here

What should I do to get normal values(null as None, integer as int) in request.data?


Solution

  • solved this by setting null values as empty strings before the patch method and by setting allow_null=True in serializers