D
D
Denis Karimov2016-08-19 22:36:32
Django
Denis Karimov, 2016-08-19 22:36:32

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)

Serializer:
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')

settings:
REST_FRAMEWORK = {
    #'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',),
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 2
}

The limit has been deliberately lowered. Psychonul stupidly) I tried to set limits, offsets, but is it reasonable ... I don’t want the REST API to have a page in general that gives out all the records.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Abdulla Mursalov, 2016-08-20
@trixden

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 question

Ask a Question

731 491 924 answers to any question