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:
Mjumbe Wawatu Poe 2012-08-25 10:54:21 -04:00
parent 912a897e2d
commit 3cef6bd02c

View File

@ -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):