From what I've read in the docs, it's impossible to change the parent of an entity after it has been put in the datastore. But I am looking for a way to change the parent before that happens (but after it is created). So instead of having this:
John = Student(parent=BlueClassroom.key, name="John", last_name="Smith")
John.put()
I am looking for something like this:
John = Student(name="John", last_name="Smith")
John.parent = BlueClassroom.key
John.put()
Now, the first one works, but the second one does not (it just ignores the second line). I have also tried to use populate, but that just works for regular properties. Is there some way to do this?
According to the NDB Model Class Constructor docs:
You cannot easily define a property named "key", "id", "parent", or "namespace". If you pass, for example, key="foo" in a constructor or populate() call, it sets the entity's key, not a property attribute named "key".
I'd suggest passing the data around as a dict until you're ready to create the entity:
john = {name="John", last_name="Smith"}
...
John = Student(parent=BlueClassroom.key)
John.populate(john)