Django Tastypie:instancemethod对象不可迭代

时间:2017-01-03 13:13:40

标签: django tastypie

尝试将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'对象不可迭代

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

感觉可能期望access_set成为@property:

class Project(models.Model):

    ...

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