mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-09-16 17:22:32 +03:00
PUT returns a 201 status when instance was created.
Note: This behavior is still idempotent, as the state of the system is the same after multiple PUT requests as it is after one. However, it is helpful to know whether an instance was created or whether it already existed.
This commit is contained in:
parent
912a897e2d
commit
3cef6bd02c
|
@ -602,10 +602,13 @@ class UpdateModelMixin(ModelMixin, ExistingInstanceMixin):
|
|||
|
||||
for (key, val) in self.CONTENT.items():
|
||||
setattr(self.model_instance, key, val)
|
||||
|
||||
self.model_instance.save()
|
||||
return self.model_instance
|
||||
except model.DoesNotExist:
|
||||
self.model_instance = model(**self.get_instance_data(model, self.CONTENT, *args, **kwargs))
|
||||
self.model_instance.save()
|
||||
return self.model_instance
|
||||
return Response(status.HTTP_201_CREATED, self.model_instance)
|
||||
|
||||
|
||||
class DeleteModelMixin(ModelMixin, ExistingInstanceMixin):
|
||||
|
|
Loading…
Reference in New Issue
Block a user