Change | Assign parent model instance to Google App Engine datastore

Is it possible to change or assign a new parent to an instance of a model that is already in the data warehouse? For example, I need something like this

task = db.get(db.Key(task_key)) project = db.get(db.Key(project_key)) task.parent = project task.put() 

but this does not work because task.parent is a built-in method. I was thinking of creating a new Key instance for the task, but there is also no way to change the key.

Any thoughts?

+6
python google-app-engine transactions google-cloud-datastore
source share
1 answer

According to docs , no:

The parent of the object is determined when the object is created, and cannot be changed later.

...

The full key of an object, including the path, view, and name or numeric identifier, is unique and specific to that object. A full key is assigned when an object is created in the data warehouse, and none of its parts can change.

Setting up a parent is useful when you need to manipulate a parent and child in the same transaction. Otherwise, you simply limit performance by forcing them both to be in the same entity group and limiting your ability to update relationships after creating the entity.

Use ReferenceProperty instead.

+9
source share

All Articles