ここでは、tastypie の Nested Resource クックブック パターンを使用していますが、多対多の関係のみを使用しています。
つまり、前に追加する URL は次のようになります。
class ParentResource(ModelResource):
children = fields.ToManyField(ChildResource, 'children')
def prepend_urls(self):
return [
url(r"^(?P<resource_name>%s)/(?P<pk>\w[\w/-]*)/childrens%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('get_children'), name="api_get_children"),
]
def get_children(self, request, **kwargs):
#some way to get the filter
child_resource = ChildResource()
return child_resource.get_list(request, parent_id=obj.pk)
ページネーションが prepend__urls の URL ではなく、子リソースの URL を使用することを除いて、これは正常に機能します。IE の代わりに:
"meta": {
"limit": 1,
"next": "/api/parent/1/childrens?limit=1&offset=1",
"offset": 0,
"previous": null,
"total_count": 2
},
私は得る:
"meta": {
"limit": 1,
"next": "/api/parent/?limit=1&offset=1",
"offset": 0,
"previous": null,
"total_count": 2
},
とにかく、ページネーションの URL を正しく表示する方法はありますか?