gpt4 book ai didi

google-app-engine - 从 appengine 中的引用属性获取实体的字符串编码键

转载 作者:太空宇宙 更新时间:2023-11-03 15:33:10 24 4
gpt4 key购买 nike

为了获取实体的字符串编码键,我只需执行以下操作:

key = entity.key()
string_encoded_key = str(key)

我通过 ReferenceProperty 引用了另一个实体。

class ParentClass(db.Model):
name = db.StringProperty()

class ChildClass(db.Model):
name = db.StringProperty()
bio_parent = db.ReferenceProperty(ParentClass)


johnnys_parent = ParentClass(name="John").put()
child = ChildClass(name="Johnny",bio_parent=johnnys_parent).put()

#getting the string-encoded key of the parent through the child
child = ChildClass.all().filter("name","Johnny").get()
string_encoded_key = str(child.bio_parent) # <--- this doesn't give me the string-encoded key

如何在不获取父实体的情况下通过子实体获取亲生 parent 的字符串编码 key ?

谢谢!

最佳答案

您无需像这样获取引用属性的键即可获取它:

ChildClass.bio_parent.get_value_for_datastore(child_instance)

从那里,您可以像往常一样获取字符串编码形式。

关于google-app-engine - 从 appengine 中的引用属性获取实体的字符串编码键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5322514/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com