0
votes

I have retrieved the object by doing the following and I am trying to update a field in the object. However, it is throwing an exception "response object has no attribute save"

def retrieve(self, request, token=None):
    object_serializer = self.serializer_class(self.get_object(token=token))
    obj = object_serializer.instance
    obj.update_field = "test field"
    obj.save()

    return Response(object_serializer.data)
1
if you have error, maybe you have problem in code, not in obj.save(). I tried and save normally.Ngoc Pham

1 Answers

0
votes

I think the logic is not correct. First saving the object and returning the updated object will be OK.

def retrieve(self, request, token=None):
    obj = self.get_object(token=token)
    obj.update_field = "test field"
    obj.save()

    object_serializer = self.serializer_class(obj)
    return Response(object_serializer.data)