How to hydrate a resource_uri in django-tastypie?

流过昼夜 提交于 2019-12-05 18:08:31

Extracted from https://gist.github.com/794424

def get_resource_uri(self, bundle_or_obj):

kwargs = {
    'resource_name': self._meta.resource_name,
}
if isinstance(bundle_or_obj, Bundle):
    kwargs['pk'] = bundle_or_obj.obj.id # pk is referenced in ModelResource
else:
    kwargs['pk'] = bundle_or_obj.id
if self._meta.api_name is not None:
    kwargs['api_name'] = self._meta.api_name
return self._build_reverse_url('api_dispatch_detail', kwargs = kwargs)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!