diff options
| author | Tom Christie | 2012-10-31 20:11:32 +0000 |
|---|---|---|
| committer | Tom Christie | 2012-10-31 20:11:38 +0000 |
| commit | 027c9079f62322fe933bdfd4438f23cf4848e3cc (patch) | |
| tree | b74c3b8ea89b91c82921f6cf055fed3fdd5321ac /rest_framework/mixins.py | |
| parent | 3a99170a7300b2212dbb5aa91c7a7262d7425e98 (diff) | |
| download | django-rest-framework-027c9079f62322fe933bdfd4438f23cf4848e3cc.tar.bz2 | |
PUT as create should return 201. Fixes #340.
Diffstat (limited to 'rest_framework/mixins.py')
| -rw-r--r-- | rest_framework/mixins.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/rest_framework/mixins.py b/rest_framework/mixins.py index 8873e4ae..0f2a0d93 100644 --- a/rest_framework/mixins.py +++ b/rest_framework/mixins.py @@ -3,9 +3,6 @@ Basic building blocks for generic class based views. We don't bind behaviour to http method handlers yet, which allows mixin classes to be composed in interesting ways. - -Eg. Use mixins to build a Resource class, and have a Router class - perform the binding of http methods to actions for us. """ from django.http import Http404 from rest_framework import status @@ -78,15 +75,17 @@ class UpdateModelMixin(object): def update(self, request, *args, **kwargs): try: self.object = self.get_object() + success_status = status.HTTP_200_OK except Http404: self.object = None + success_status = status.HTTP_201_CREATED serializer = self.get_serializer(data=request.DATA, instance=self.object) if serializer.is_valid(): self.pre_save(serializer.object) self.object = serializer.save() - return Response(serializer.data) + return Response(serializer.data, status=success_status) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) |
