1

我有这个美味的资源:

class BlogPostResource(ModelResource):
    comments = fields.ToManyField('comments.api.CommentResource', 'comments', full=True)

博客端点/api/v1/blog/13返回以下响应:

{
  id: 13,
  text: 'blog example',
  comments: [{id: 1, comment: "1"},{id: 2, comment: "2"}, ...]
}

我期待评论会像这样分页:

{
  id: 13,
  text: 'blog example',
  comments:{
    meta: {
      limit: 20,
      next: "/api/v1/comment/?offset=20&limit=20&format=json", 
      offset: 0,
      previous: null,
      total_count: 36
    },
    objects: [{id: 1, comment: "1"},{id: 2, comment: "2"}, ...]
  }
}

如何使评论分页以获得我所期望的响应?

4

0 回答 0