gpt4 book ai didi

google-app-engine - 谷歌应用引擎 : reference property that references to 4 models or more

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

你好我需要向可以引用 4 个不同模型的模型添加一个属性:

class WorldObject(db.Model):
# type can only accept: text, image, profile, position
# this should be like a set property in relational database and not a string
type = db.StringProperty(required = True)

# ???: this can be a reference to Profile, Image, Position or Text model
# how to do it?
reference = db.ReferenceProperty(reference_class = ???, required = True)

谢谢


@尼克约翰逊:

以下是我在您的帮助下完成的工作:

class WorldObject(db.Model):
# x, y: position in the world
x = db.IntegerProperty(required = True)
y = db.IntegerProperty(required = True)

# world: reference to the world containing it
world = db.ReferenceProperty(reference_class = World)

# profile: is the owner of the object and is the only one who can make changes to it's world object property
owner = db.ReferenceProperty(reference_class = Profile, required = False)

# history
updated = db.DateTimeProperty(auto_now_add = True)
created = db.DateTimeProperty(required = True)

然后:

class ImageWO(WorldObject):
image = db.ReferenceProperty(reference_class = Image, required = False)

然后:

class PositionWO(WorldObject):
position = db.ReferenceProperty(reference_class = Position, required = False)

和其他类是一样的..现在,如果我想获得一个区域中的所有世界对象,我该怎么做?我必须为扩展 world_object 的每个类执行 1 个请求?

最佳答案

Make ProfileImagePositionText 都扩展了同一个基类,它本身扩展了 Model .然后,将该基类指定为 ReferenceProperty 的目标。无需在 StringProperty 中存储单独的“类型”——这将反射(reflect)在为引用属性存储的键中。

关于google-app-engine - 谷歌应用引擎 : reference property that references to 4 models or more,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3562332/

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