[Python] Queryset pagination in websocket django rest framework [closed]

Discussão em 'Python' iniciado por Stack, Fevereiro 3, 2025.

  1. Stack

    Stack Membro Participativo

    I have a websocket in my django drf project and a function that should read all of Notification objects from database and return them via a serializer like bellow :

    @database_sync_to_async
    def get_all_notifications(self):
    paginator = CustomPageNumberPagination()
    notifications = Notification.objects.all().order_by('-created_at')
    context = paginator.paginate_queryset(notifications, WhatQuery?)
    serializer = NotificationSerializer(context=context, many=True)
    return paginator.get_paginated_response(serializer.data)


    I do not know how to get request in socket and I think it is not accessable in socket


    paginator.paginate_queryset(queryset, request)
    ​

    my CustomPagination is as bellow :

    from rest_framework.pagination import PageNumberPagination


    class CustomPageNumberPagination(PageNumberPagination):
    page_size = 15
    page_size_query_param = 'page_size'
    max_page_size = 1000


    what is the solution here?

    Continue reading...

Compartilhe esta Página