使用游标分页进行分页

时间:2019-01-20 13:39:19

标签: python django pagination django-rest-framework twitter-feed

我有一个api端点,可在其中使用CursorPagination对标签进行分页。

class Tag(models.Model):
    name = models.CharField(max_length=50)
    created_at = models.DateTimeField(auto_now_add=True)

class CursorSetPagination(CursorPagination):
    page_size = 15
    page_size_query_param = 'page_size'
    ordering = '-created_at'

class TagViewSet(ModelViewSet):
    serializer_class = TagSerializer
    queryset = Tag.objects.all()
    pagination_class = CursorSetPagination

现在,移动客户端用户位于第一页上。响应将如下所示

{
    "next": "http://0.0.0.0:8000/api/tags/?cursor=cD0xMDk1ODQ%3D",
    "previous": null,
    "results": [
        {
            "id": 109598,
            "name": "foobar"
        },
        {
            "id": 109597,
            "name": "displeas"
        }
    ]
}

已创建一些新标签。那么我的移动客户端如何知道此更新?

0 个答案:

没有答案