I am trying to get the parent key from a certain entity.
I have 2 classes, Album and Photo. Album is a parent to photo, so when I upload a photo I assign the key of that certain album it belongs to as a parent to the photo.
album = db.get(self.album_key)
photo = Photo(parent=album)
Problem arises when I try to query for the parent id from photo. The below code just gives me an output of “parent key: <“
photo = db.get(photo_key)
photoparent = photo.parent
self.response.out.write("parent key: %s" %photoparent)
How can I properly pull the parent key from a Photo instance?
Thanks!
parent is a method call, not a property.
So you code should read
See docs https://developers.google.com/appengine/docs/python/datastore/modelclass#Model_parent
Also when the key is output in
The keys str method outputs a representation of the object with <>’s So you may want to do something with the parent to make it’s html output more sane 😉
Cheers
Tim