From c678a1f118ea65fc1d13c40ef1a083577fdd5381 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 18 Dec 2014 13:49:50 +0000 Subject: Update documentation --- tutorial/6-viewsets-and-routers/index.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tutorial/6-viewsets-and-routers/index.html') diff --git a/tutorial/6-viewsets-and-routers/index.html b/tutorial/6-viewsets-and-routers/index.html index 04071f9e..03839e8d 100644 --- a/tutorial/6-viewsets-and-routers/index.html +++ b/tutorial/6-viewsets-and-routers/index.html @@ -251,6 +251,10 @@ Contributing to REST framework +
  • + Project management +
  • +
  • 2.0 Announcement
  • @@ -423,8 +427,8 @@ class SnippetViewSet(viewsets.ModelViewSet): snippet = self.get_object() return Response(snippet.highlighted) - def pre_save(self, obj): - obj.owner = self.request.user + def perform_create(self, serializer): + serializer.save(owner=self.request.user)

    This time we've used the ModelViewSet class in order to get the complete set of default read and write operations.

    Notice that we've also used the @detail_route decorator to create a custom action, named highlight. This decorator can be used to add any custom endpoints that don't fit into the standard create/update/delete style.

    -- cgit v1.2.3