Answer the question
In order to leave comments, you need to log in
Django Rest Framework - limits not working?
Good day. I ask for help, because the problem has been haunting for the second day. I've been pulling up the Django Rest Framework for a week now (because TastyPie is sooo limited). And the problem that I encountered is primitive to the point of pain. No, well, they are not limited by the recording limit.
I tried how to limit myself in the tutorial to only writing PAGE_SIZE in configs. I tried to substitute the paginator class, out of desperation I even tried to write my own paginator - it stupidly gives out all the records and even cracks.
System Information:
Serializers on HyperlinkedModelSerializer
Views on ViewSet
Updated
ViewSet:
class BlogPostsViewSet (viewsets.ViewSet):
queryset = BlogModels.Posts.objects.all()
lookup_field = 'alias'
def list(self, request):
serializer = BlogPostsListSerializer(self.queryset, many=True)
return Response(serializer.data)
class BlogPostsListSerializer (serializers.HyperlinkedModelSerializer):
category = BlogCategoriesSerializer()
class Meta:
model = BlogModels.Posts
lookup_field = 'alias'
extra_kwargs = {
'url': {'lookup_field': 'alias'}
}
fields = ('id', 'alias', 'title', 'image', 'subtext', 'publish', 'created', 'category')
REST_FRAMEWORK = {
#'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',),
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 2
}
Answer the question
In order to leave comments, you need to log in
You defined the list method without including pagination in it. Use a list mixin or just take a ModelViewSet.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question