I have a model which has has an primary key id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
.
When a PUT
request is sent to the resource's endpoint /api/v1/resource/<id>.json
I would like to create a new resource with the supplied id
if the resource does not already exist.
Note: I'm using a ModelViewSet
with a ModelSerializer
What is the most elegant way of doing this?
I ended up overriding the
get_object()
method in myModelViewSet
:Perhaps there's a more elegant way of doing this?