aboutsummaryrefslogtreecommitdiffstats
path: root/docs/api-guide/viewsets.md
diff options
context:
space:
mode:
authorTom Christie2013-06-28 09:07:09 +0100
committerTom Christie2013-06-28 09:07:09 +0100
commit58d38d694eba94d4c6c20edcbefb5f4f91e6dd0f (patch)
treeba72bed1f1f20bed9d023fb076e0adcf7e92abf1 /docs/api-guide/viewsets.md
parentde00ec95c3007dd90b5b01f7486b430699ea63c1 (diff)
parent1f6a59d76da286e7a89e8e41317beb16a4aab7c7 (diff)
downloaddjango-rest-framework-58d38d694eba94d4c6c20edcbefb5f4f91e6dd0f.tar.bz2
Merge branch 'master' into writable-nested-modelserializer
Diffstat (limited to 'docs/api-guide/viewsets.md')
-rw-r--r--docs/api-guide/viewsets.md16
1 files changed, 7 insertions, 9 deletions
diff --git a/docs/api-guide/viewsets.md b/docs/api-guide/viewsets.md
index 2783da98..25d11bfb 100644
--- a/docs/api-guide/viewsets.md
+++ b/docs/api-guide/viewsets.md
@@ -27,7 +27,7 @@ Let's define a simple viewset that can be used to list or retrieve all the users
queryset = User.objects.all()
serializer = UserSerializer(queryset, many=True)
return Response(serializer.data)
-
+
def retrieve(self, request, pk=None):
queryset = User.objects.all()
user = get_object_or_404(queryset, pk=pk)
@@ -69,7 +69,7 @@ The default routers included with REST framework will provide routes for a stand
"""
Example empty viewset demonstrating the standard
actions that will be handled by a router class.
-
+
If you're using format suffixes, make sure to also include
the `format=None` keyword argument for each action.
"""
@@ -103,12 +103,12 @@ For example:
class UserViewSet(viewsets.ModelViewSet):
"""
- A viewset that provides the standard actions
+ A viewset that provides the standard actions
"""
queryset = User.objects.all()
serializer_class = UserSerializer
-
- @action
+
+ @action()
def set_password(self, request, pk=None):
user = self.get_object()
serializer = PasswordSerializer(data=request.DATA)
@@ -197,7 +197,7 @@ As with `ModelViewSet`, you'll normally need to provide at least the `queryset`
Again, as with `ModelViewSet`, you can use any of the standard attributes and method overrides available to `GenericAPIView`.
-# Custom ViewSet base classes
+# Custom ViewSet base classes
You may need to provide custom `ViewSet` classes that do not have the full set of `ModelViewSet` actions, or that customize the behavior in some other way.
@@ -209,11 +209,9 @@ To create a base viewset class that provides `create`, `list` and `retrieve` ope
mixins.ListMixin,
mixins.RetrieveMixin,
viewsets.GenericViewSet):
- pass
-
"""
A viewset that provides `retrieve`, `update`, and `list` actions.
-
+
To use it, override the class and set the `.queryset` and
`.serializer_class` attributes.
"""