diff options
| author | Tom Christie | 2013-01-02 13:46:19 +0000 |
|---|---|---|
| committer | Tom Christie | 2013-01-02 13:46:19 +0000 |
| commit | ef73160599ef836f47801fe550168ecdaa3e20d6 (patch) | |
| tree | ebd6727f2d95813f3e6efd4de07a7027e236ef31 | |
| parent | b807f3d52a68dbf657c6437f71ecbfcba0695972 (diff) | |
| parent | 76c840f1bb3b934dc2127faa04704ab4b11a018b (diff) | |
| download | django-rest-framework-ef73160599ef836f47801fe550168ecdaa3e20d6.tar.bz2 | |
Added `RetrieveUpdateAPIView`
| -rw-r--r-- | docs/api-guide/generic-views.md | 14 | ||||
| -rw-r--r-- | docs/topics/release-notes.md | 6 | ||||
| -rw-r--r-- | rest_framework/generics.py | 13 |
3 files changed, 29 insertions, 4 deletions
diff --git a/docs/api-guide/generic-views.md b/docs/api-guide/generic-views.md index 27c7d3f6..693e210d 100644 --- a/docs/api-guide/generic-views.md +++ b/docs/api-guide/generic-views.md @@ -85,7 +85,7 @@ Extends: [SingleObjectAPIView], [DestroyModelMixin] Used for **update-only** endpoints for a **single model instance**. -Provides a `put` method handler. +Provides `put` and `patch` method handlers. Extends: [SingleObjectAPIView], [UpdateModelMixin] @@ -97,6 +97,14 @@ Provides `get` and `post` method handlers. Extends: [MultipleObjectAPIView], [ListModelMixin], [CreateModelMixin] +## RetrieveUpdateAPIView + +Used for **read or update** endpoints to represent a **single model instance**. + +Provides `get`, `put` and `patch` method handlers. + +Extends: [SingleObjectAPIView], [RetrieveModelMixin], [UpdateModelMixin] + ## RetrieveDestroyAPIView Used for **read or delete** endpoints to represent a **single model instance**. @@ -109,7 +117,7 @@ Extends: [SingleObjectAPIView], [RetrieveModelMixin], [DestroyModelMixin] Used for **read-write-delete** endpoints to represent a **single model instance**. -Provides `get`, `put` and `delete` method handlers. +Provides `get`, `put`, `patch` and `delete` method handlers. Extends: [SingleObjectAPIView], [RetrieveModelMixin], [UpdateModelMixin], [DestroyModelMixin] @@ -197,6 +205,8 @@ If an object is created, for example when making a `DELETE` request followed by If the request data provided for updating the object was invalid, a `400 Bad Request` response will be returned, with the error details as the body of the response. +A boolean `partial` keyword argument may be supplied to the `.update()` method. If `partial` is set to `True`, all fields for the update will be optional. This allows support for HTTP `PATCH` requests. + Should be mixed in with [SingleObjectAPIView]. ## DestroyModelMixin diff --git a/docs/topics/release-notes.md b/docs/topics/release-notes.md index 5b34bf3d..e4bd1217 100644 --- a/docs/topics/release-notes.md +++ b/docs/topics/release-notes.md @@ -18,7 +18,9 @@ Major version numbers (x.0.0) are reserved for project milestones. No major poi ### Master -* Relation changes are no longer persisted in `.restore_object` +* Added `PATCH` support. +* Added `RetrieveUpdateAPIView`. +* Relation changes are now persisted in `save` instead of in `.restore_object`. ### 2.1.14 @@ -61,7 +63,7 @@ This change will not affect user code, so long as it's following the recommended * Bugfix: Ensure read-only fields don't have model validation applied. * Bugfix: Fix hyperlinked fields in paginated results. -### 2.1.9 +## 2.1.9 **Date**: 11th Dec 2012 diff --git a/rest_framework/generics.py b/rest_framework/generics.py index 3a38fab4..cda9ca79 100644 --- a/rest_framework/generics.py +++ b/rest_framework/generics.py @@ -191,6 +191,19 @@ class ListCreateAPIView(mixins.ListModelMixin, return self.create(request, *args, **kwargs) +class RetrieveUpdateAPIView(mixins.RetrieveModelMixin, + mixins.UpdateModelMixin, + SingleObjectAPIView): + """ + Concrete view for retrieving, updating a model instance. + """ + def get(self, request, *args, **kwargs): + return self.retrieve(request, *args, **kwargs) + + def put(self, request, *args, **kwargs): + return self.update(request, *args, **kwargs) + + class RetrieveDestroyAPIView(mixins.RetrieveModelMixin, mixins.DestroyModelMixin, SingleObjectAPIView): |
