diff options
| author | Tom Christie | 2013-04-26 13:31:19 +0100 |
|---|---|---|
| committer | Tom Christie | 2013-04-26 13:31:19 +0100 |
| commit | 50c6bc5762460ebd2a79b61edd534d10cb58c7e5 (patch) | |
| tree | dcc3a4393d285354f1cddcaa1a89f30e7d828adf /docs | |
| parent | 51f80c3604d9257a3f3c3aa9e3e9b02b6cebb98a (diff) | |
| download | django-rest-framework-50c6bc5762460ebd2a79b61edd534d10cb58c7e5.tar.bz2 | |
Fix up viewset docs slightly
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/api-guide/viewsets.md | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/docs/api-guide/viewsets.md b/docs/api-guide/viewsets.md index 1bca491d..36a4dbd5 100644 --- a/docs/api-guide/viewsets.md +++ b/docs/api-guide/viewsets.md @@ -19,7 +19,7 @@ Typically, rather than exlicitly registering the views in a viewset in the urlco Let's define a simple viewset that can be used to listing or retrieving all the users in the system. - class UserViewSet(ViewSet): + class UserViewSet(viewsets.ViewSet): """ A simple ViewSet that for listing or retrieving users. """ @@ -45,6 +45,15 @@ Typically we wouldn't do this, but would instead register the viewset with a rou router.register(r'users', UserViewSet, 'user') urlpatterns = router.urls +Rather than writing your own viewsets, you'll often want to use the existing base classes that provide a default set of behavior. For example: + + class UserViewSet(viewsets.ModelViewSet): + """ + A viewset for viewing and editing user instances. + """ + serializer_class = UserSerializer + queryset = User.objects.all() + There are two main advantages of using a `ViewSet` class over using a `View` class. * Repeated logic can be combined into a single class. In the above example, we only need to specify the `queryset` once, and it'll be used across multiple views. @@ -60,6 +69,9 @@ 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. """ def list(self, request): @@ -197,4 +209,4 @@ For example, we can create a base viewset class that provides `retrieve`, `updat By creating your own base `ViewSet` classes, you can provide common behavior that can be reused in multiple views across your API. -[cite]: http://guides.rubyonrails.org/routing.html
\ No newline at end of file +[cite]: http://guides.rubyonrails.org/routing.html |
