【发布时间】:2018-04-10 21:12:55
【问题描述】:
tastepie 是否可以理解我希望它使用相同的授权方法从嵌套资源中过滤掉对象?
class ProjectResource(ModelResource):
def authorized_read_list(self, object_list, bundle):
return object_list.filter(user=bundle.request.user) # return projects only the user created
class ProjectGroupResource(ModelResource):
projects = ToManyField(
ProjectResource,
attribute='projects',
null=True,
blank=True
)
访问ProjectGroupResource 时不会触发authorized_read_list 方法,因此我得到了所有项目,包括非用户创建的项目。我的假设是,由于我传递了一个 ProjectResource ref,它会尝试模拟一个 get_object_list,这应该会触发包中的 authorized_read_list。
【问题讨论】:
标签: tastypie