Skip to content

Commit

Permalink
Merge pull request #2890 from radyz/fixed-doc-for-get-paginated-respo…
Browse files Browse the repository at this point in the history
…nse-method

Document correct method usage for get_paginated_response
  • Loading branch information
tomchristie committed May 5, 2015
2 parents 4db35a2 + 2b4dd73 commit 2e85b4e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/api-guide/generic-views.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ You won't typically need to override the following methods, although you might n

* `get_serializer_context(self)` - Returns a dictionary containing any extra context that should be supplied to the serializer. Defaults to including `'request'`, `'view'` and `'format'` keys.
* `get_serializer(self, instance=None, data=None, files=None, many=False, partial=False, allow_add_remove=False)` - Returns a serializer instance.
* `get_pagination_serializer(self, page)` - Returns a serializer instance to use with paginated data.
* `get_paginated_response(self, data)` - Returns a paginated style `Response` object.
* `paginate_queryset(self, queryset)` - Paginate a queryset if required, either returning a page object, or `None` if pagination is not configured for this view.
* `filter_queryset(self, queryset)` - Given a queryset, filter it with whichever filter backends are in use, returning a new queryset.

Expand Down
7 changes: 6 additions & 1 deletion docs/api-guide/viewsets.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,13 @@ For example:
@list_route()
def recent_users(self, request):
recent_users = User.objects.all().order('-last_login')

page = self.paginate_queryset(recent_users)
serializer = self.get_pagination_serializer(page)
if page is not None:
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)

serializer = self.get_serializer(recent_users, many=True)
return Response(serializer.data)

The decorators can additionally take extra arguments that will be set for the routed view only. For example...
Expand Down

0 comments on commit 2e85b4e

Please sign in to comment.