Search code examples
djangotastypie

Django Tastypie: instancemethod object is not iterable


Trying to add ToManyField to the resource. Here is the model:

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

Here is the resource:

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

I have the error: 'instancemethod' object is not iterable

Any thoughts please?


Solution

  • It feels like it could be expecting access_set to be a @property:

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