Get the parent key of the data warehouse object

I am trying to get the parent key of a specific object. I have 2 classes, an album and a photo. The album is the parent of the photo, so when I upload a photo, I assign the key to this or that album that it belongs to the parent photo.

album = db.get(self.album_key) photo = Photo(parent=album) 

The problem occurs when I try to request the parent id from the photo. The code below simply displays the output "parent key: <"

 photo = db.get(photo_key) photoparent = photo.parent self.response.out.write("parent key: %s" %photoparent) 

How to correctly remove the parent key from an instance of Photo?

Thanks!

+4
source share
1 answer

parent is a method call, not a property.

So the code should read

photoparent = photo.parent ()

See docs https://developers.google.com/appengine/docs/python/datastore/modelclass#Model_parent

Also, when the key is displayed in

self.response.out.write ("parent key:% s"% photoparent)

The str key displays the representation of the object using <> So you can do something with the parent to make its html output more reasonable; -)

Greetings

Tim

+3
source

All Articles