An attempt to model many-to-many relationships with ndb. Can anyone point out a good example of how to do this?
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 it correct? I looked around well, but I can not find good documentation on this.
In the data warehouse viewer, I see that this relation is stored as a list of keys that I expect.
However, when I try to use them in methods of the Person class, for example:
for guild in self.guilds:
I get:
TypeError: 'KeyProperty' object is not iterable
python google-app-engine many-to-many app-engine-ndb
chrisw
source share