Django Tastypie:实例方法对象不可迭代

Django Tastypie: instancemethod object is not iterable

正在尝试将 ToManyField 添加到资源中。这是模型:

class Project(models.Model):
...
def access_set(self):
    return User.objects.all()

这是资源:

class ProjectResource(ModelResource):
...
access = fields.ToManyField(UserResource, attribute = 'access_set', readonly=True, null=True)
...

我遇到错误:'instancemethod' 对象不可迭代

有什么想法吗?

感觉可以期待access_set成为@属性:

class Project(models.Model):

    ...

    @property
    def access_set(self):
        return User.objects.all()