Question

I do not really understand what does the key.from_path() do.

If you could explained it a little better and more concise then here.

Also, the parent parameter intrigues me .

Was it helpful?

Solution

Every item in the datastore has a key.

k = Key.from_path('User', 'Boris', 'Address', 9876)

You can either create that key and then use it to retrieve the object in the datastore that has that key or you can save an object to the datastore with that key for later retrieval.

address_k is a key after this operation.

address_k = db.Key.from_path('Employee', 'asalieri', 'Address', 1)
address = db.get(address_k)

Then the second line gets the datastore object that has that key.

Parent simply says that this object is a child of another object. So when you set the parent it becomes part of the key also.

address = Address(parent=employee)

You could have multiple address objects, all with the same parent, employee. Your employee might have many homes! Read this: https://developers.google.com/appengine/docs/python/datastore/entities#Ancestor_Paths

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top