Created
January 7, 2016 07:06
-
-
Save tzangms/ab442e0d0747f201c54d to your computer and use it in GitHub Desktop.
DRF pagination example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@detail_route() | |
def posts(self, request, pk=None): | |
""" | |
Photos of current user | |
""" | |
user = self.get_object() | |
photos = Photo.objects.filter(user=user) | |
queryset = self.paginate_queryset(photos) | |
if queryset is not None: | |
serializer = PhotoSerializer(queryset, many=True, context={'request': request}) | |
return self.get_paginated_response(serializer.data) | |
serializer = PhotoSerializer(photos, many=True, context={'request': request}) | |
return Response(serializer.data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment