aboutsummaryrefslogtreecommitdiffstats
path: root/docs/api-guide/generic-views.md
diff options
context:
space:
mode:
authorTom Christie2012-10-05 05:11:17 -0700
committerTom Christie2012-10-05 05:11:17 -0700
commit2455bebd8733a11ba06dfbc33f9f2378025f538c (patch)
treeaeacef5a09d7bd815dd02fcb0baa5a81d777c9c5 /docs/api-guide/generic-views.md
parent5a14e3eff29c1c28ab1c217680d9f25b92405221 (diff)
parent61a6d0c1094706db137b2fe57f117f263a61923d (diff)
downloaddjango-rest-framework-2455bebd8733a11ba06dfbc33f9f2378025f538c.tar.bz2
Merge pull request #282 from tomchristie/html-template-responses
Html template responses
Diffstat (limited to 'docs/api-guide/generic-views.md')
-rw-r--r--docs/api-guide/generic-views.md29
1 files changed, 23 insertions, 6 deletions
diff --git a/docs/api-guide/generic-views.md b/docs/api-guide/generic-views.md
index b2284ae5..571cc66f 100644
--- a/docs/api-guide/generic-views.md
+++ b/docs/api-guide/generic-views.md
@@ -18,24 +18,25 @@ If the generic views don't suit the needs of your API, you can drop down to usin
Typically when using the generic views, you'll override the view, and set several class attributes.
class UserList(generics.ListCreateAPIView):
- serializer = UserSerializer
model = User
- permissions = (IsAdminUser,)
+ serializer_class = UserSerializer
+ permission_classes = (IsAdminUser,)
paginate_by = 100
For more complex cases you might also want to override various methods on the view class. For example.
class UserList(generics.ListCreateAPIView):
- serializer = UserSerializer
model = User
- permissions = (IsAdminUser,)
+ serializer_class = UserSerializer
+ permission_classes = (IsAdminUser,)
def get_paginate_by(self):
"""
Use smaller pagination for HTML representations.
"""
- if self.request.accepted_media_type == 'text/html':
- return 10
+ page_size_param = self.request.QUERY_PARAMS.get('page_size')
+ if page_size_param:
+ return int(page_size_param)
return 100
For very simple cases you might want to pass through any class attributes using the `.as_view()` method. For example, your URLconf might include something the following entry.
@@ -52,24 +53,32 @@ Used for read-only endpoints to represent a collection of model instances.
Provides a `get` method handler.
+Extends: [MultipleObjectBaseAPIView], [ListModelMixin]
+
## ListCreateAPIView
Used for read-write endpoints to represent a collection of model instances.
Provides `get` and `post` method handlers.
+Extends: [MultipleObjectBaseAPIView], [ListModelMixin], [CreateModelMixin]
+
## RetrieveAPIView
Used for read-only endpoints to represent a single model instance.
Provides a `get` method handler.
+Extends: [SingleObjectBaseAPIView], [RetrieveModelMixin]
+
## RetrieveUpdateDestroyAPIView
Used for read-write endpoints to represent a single model instance.
Provides `get`, `put` and `delete` method handlers.
+Extends: [SingleObjectBaseAPIView], [RetrieveModelMixin], [UpdateModelMixin], [DestroyModelMixin]
+
---
# Base views
@@ -123,3 +132,11 @@ Provides a `.destroy(request, *args, **kwargs)` method, that implements deletion
[SingleObjectMixin]: https://docs.djangoproject.com/en/dev/ref/class-based-views/mixins-single-object/
[multiple-object-mixin-classy]: http://ccbv.co.uk/projects/Django/1.4/django.views.generic.list/MultipleObjectMixin/
[single-object-mixin-classy]: http://ccbv.co.uk/projects/Django/1.4/django.views.generic.detail/SingleObjectMixin/
+
+[SingleObjectBaseAPIView]: #singleobjectbaseapiview
+[MultipleObjectBaseAPIView]: #multipleobjectbaseapiview
+[ListModelMixin]: #listmodelmixin
+[CreateModelMixin]: #createmodelmixin
+[RetrieveModelMixin]: #retrievemodelmixin
+[UpdateModelMixin]: #updatemodelmixin
+[DestroyModelMixin]: #destroymodelmixin \ No newline at end of file