Added RetrieveUpdateAPIView

This commit is contained in:
Tom Christie 2013-01-02 13:46:19 +00:00
commit ef73160599
3 changed files with 29 additions and 4 deletions

View File

@ -85,7 +85,7 @@ Extends: [SingleObjectAPIView], [DestroyModelMixin]
Used for **update-only** endpoints for a **single model instance**. Used for **update-only** endpoints for a **single model instance**.
Provides a `put` method handler. Provides `put` and `patch` method handlers.
Extends: [SingleObjectAPIView], [UpdateModelMixin] Extends: [SingleObjectAPIView], [UpdateModelMixin]
@ -97,6 +97,14 @@ Provides `get` and `post` method handlers.
Extends: [MultipleObjectAPIView], [ListModelMixin], [CreateModelMixin] 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 ## RetrieveDestroyAPIView
Used for **read or delete** endpoints to represent a **single model instance**. 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**. 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] 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. 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]. Should be mixed in with [SingleObjectAPIView].
## DestroyModelMixin ## DestroyModelMixin

View File

@ -18,7 +18,9 @@ Major version numbers (x.0.0) are reserved for project milestones. No major poi
### Master ### 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 ### 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: Ensure read-only fields don't have model validation applied.
* Bugfix: Fix hyperlinked fields in paginated results. * Bugfix: Fix hyperlinked fields in paginated results.
### 2.1.9 ## 2.1.9
**Date**: 11th Dec 2012 **Date**: 11th Dec 2012

View File

@ -191,6 +191,19 @@ class ListCreateAPIView(mixins.ListModelMixin,
return self.create(request, *args, **kwargs) 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, class RetrieveDestroyAPIView(mixins.RetrieveModelMixin,
mixins.DestroyModelMixin, mixins.DestroyModelMixin,
SingleObjectAPIView): SingleObjectAPIView):