Skip to content Skip to sidebar Skip to footer

Adding A StructuredProperty To A Model In NDB

(couldn't think of a better title :S ) So I've recently changed from db to ndb and i can't get one part to work. I have this tutorial model that has chapters, so I am using 'ndb.St

Solution 1:

You seem to be confused. When using StructuredProperty, the contained object doesn't have its own ID or key -- it's just more properties with funny names in the outer object. Perhaps you want a repeated KeyProperty linking the book to its chapters rather than having all the chapters contained inside the book? You have to choose one or the other.


Solution 2:

You are dealing with a list... you need to append the object to the list

tutorialInstance.chapters.append(chap)

Solution 3:

Update: with the help of @nizz, changing

tutorialInstance = tutorial.get()
tutorialInstance.chapters = chap

to:

tutorialInstance = ndb.Key('Tutorial', int(tutID)).get()
tutorialInstance.chapters.append(chap)

worked perfectly.


Post a Comment for "Adding A StructuredProperty To A Model In NDB"