Given
class Category(db.Model): name = db.Stringproperty()
Say I have a nested hierarchy
-root
|-a
| |-b
| |-c
|-x
|-y
|-z1
|-z2
where a‘s parent is root, b‘s parent is a, c‘s parent is b etc.
Is there a simple way by which I could move node y from x to b such that z1 and z2 continue to remain children of y:
-root |-a | |-b | |-c | |-y | |-z1 | |-z2 |-x
That would mean I simply change y‘s parent.
However, if that is not possible than it would require
- creating a new record
ny = Category(parent=b, name=y)and - recursively for each child of
ycreating a new record that hasnyas a parent and - than deleting
yand its children.
The parent relationship is encoded in an entity’s key, and the key is immutable once created, so no, you can’t change the key of an existing entity. In order to do so, you need to reinsert all the relevant items with new keys.