尝试将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'对象不可迭代
有什么想法吗?
答案 0 :(得分:1)
感觉可能期望access_set
成为@property:
class Project(models.Model):
...
@property
def access_set(self):
return User.objects.all()