Django tastypie嵌套到了多个字段分页

时间:2013-01-01 13:02:32

标签: python django tastypie

我有这个tastypie资源:

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"}, ...]
  }
}

如何对评论进行分页以获得我期待的响应?

0 个答案:

没有答案