Trying to model a many-to-many relationship with ndb. Can anyone point to a good example of how to do this?
At here is an example of what I have at the moment:
class Person(ndb.Model):
guilds = ndb.KeyProperty(kind="Guild", repeated=True)
class Guild(ndb.Model)
members = ndb.KeyProperty(kind="Person", repeated=True)
def add_person(self, person):
self.members.append(person.key)
self.put()
person.guilds.append(self.key)
person.put()
Is this the correct way to go about it? I have had a good look around but can't seem to find any good documentation on the subject.
In the datastore viewer, I can see this relationship being stored as a list of Keys, which I expect.
However, when I try to use them in the Person class methods like this:
for guild in self.guilds:
I get:
TypeError: 'KeyProperty' object is not iterable
for guild in self.guilds
should work. Check againt if you putrepeated=True
in Person:guilds = ndb.KeyProperty(kind="Guild", repeated=True)
– Saum