开发者

How can I get the key_name of the entry in Model() on GAE for Python?

开发者 https://www.devze.com 2023-01-26 08:52 出处:网络
I have a Model() called Member and I\'m inserting new entries using Member.get_or_insert(key_name=\'lipis\') for example.

I have a Model() called Member and I'm inserting new entries using Member.get_or_insert(key_name='lipis') for example.

My question is how can I get a key_name that I used to insert a n开发者_运维知识库ew entry for a specific member?


Do you mean how do you then find that record using the key name, or how do you take an entity and find its key name?

To get that record back out of the datastore, do:

myMember = Member.get_by_key_name('lipis')

...if you have the member record and want to get its key name, you can then do:

keyName = myMember.key().name()


You actually use key().name():

lipis = Member.get_or_insert(key_name='lipis')
key_name = lipis.key().name()

If it was inserted with a key_name (and not an id), that will return it.

0

精彩评论

暂无评论...
验证码 换一张
取 消