[Answered ]-Return newly created object after creation with ModelViewSet

1👍

It’s a viewset, it needs to return HTTP response to client, from the link you posted you can access it via serializer.instance:

You can access the object through serializer.instance

But you have to process the request and create the instance first:

def perform_create(self, serializer):
    # call parent class implementation to create the instance
    response = super().perform_create(serializer)
    # now you can access it via serializer
    instance = serializer.instance
    # return the response to the client
    return response
    

Leave a comment