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

Using Authorization methods on a nested Resource

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 ref,它会尝试模拟一个 get_object_list,这应该会触发 authorized_read_list 与 bundle。

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

不过您的 authorized_read_list 方法似乎缺少 return statement