aboutsummaryrefslogtreecommitdiffstats
path: root/docs/tutorial/6-viewsets-and-routers.md
diff options
context:
space:
mode:
authorTom Christie2013-04-04 20:35:40 +0100
committerTom Christie2013-04-04 20:35:40 +0100
commitfb41d2ac8f495ae0728e3f38c6a21306f0507316 (patch)
tree8dc1c7acb4778b900eaef144bd2e1857216d72a1 /docs/tutorial/6-viewsets-and-routers.md
parentc785628300d2b7cce63862a18915c537f8a3ab24 (diff)
downloaddjango-rest-framework-fb41d2ac8f495ae0728e3f38c6a21306f0507316.tar.bz2
Add support for action and link routing
Diffstat (limited to 'docs/tutorial/6-viewsets-and-routers.md')
-rw-r--r--docs/tutorial/6-viewsets-and-routers.md15
1 files changed, 14 insertions, 1 deletions
diff --git a/docs/tutorial/6-viewsets-and-routers.md b/docs/tutorial/6-viewsets-and-routers.md
index 9c8a218f..8a2108b3 100644
--- a/docs/tutorial/6-viewsets-and-routers.md
+++ b/docs/tutorial/6-viewsets-and-routers.md
@@ -12,13 +12,26 @@ Let's take our current set of views, and refactor them into view sets.
First of all let's refactor our `UserListView` and `UserDetailView` views into a single `UserViewSet`. We can remove the two views, and replace then with a single class:
- class UserViewSet(viewsets.ModelViewSet):
+ class UserViewSet(viewsets.ReadOnlyModelViewSet):
+ """
+ This viewset automatically provides `list` and `detail` actions.
+ """
queryset = User.objects.all()
serializer_class = UserSerializer
Next we're going to replace the `SnippetList`, `SnippetDetail` and `SnippetHighlight` view classes. We can remove the three views, and again replace them with a single class.
+ from rest_framework import viewsets
+ from rest_framework.decorators import link
+
class SnippetViewSet(viewsets.ModelViewSet):
+ """
+ This viewset automatically provides `list`, `create`, `retrieve`,
+ `update` and `destroy` actions.
+
+ Additionally we provide an extra `highlight` action, by using the
+ `@link` decorator.
+ """
queryset = Snippet.objects.all()
serializer_class = SnippetSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,