在嵌套资源上使用授权方法

时间:2018-04-10 21:12:56

标签: tastypie

tastypie是否有可能理解我希望它使用相同的授权方法从嵌套资源中过滤掉对象?

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
    )

访问authorized_read_list时,ProjectGroupResource方法不会触发,因此我获得了所有项目,包括非用户创建的项目。我假设因为我传递了一个ProjectResource引用,它会尝试模拟一个get_object_list,它应该触发与bundle一起的authorized_read_list。

1 个答案:

答案 0 :(得分:1)

自从我使用Tastypie以来已经有一段时间了,但我认为authorized_*方法仅在直接使用时适用于该资源,而不是在使用资源序列化相关属性时。

看起来您的authorized_read_list方法缺少返回statement

相关问题