gpt4 book ai didi

python - 另一个 StructuredProperty 中的 StructuredProperty。如何?

转载 作者:太空宇宙 更新时间:2023-11-03 12:39:55 26 4
gpt4 key购买 nike

我有一个实体,其中有一个可变数量的另一个实体(所以我使用结构化属性,repeated=True),但是一个属性也可以容纳可变数量的单一实体类型。所以我的代码看起来像这样:

class Property(ndb.Model):
name = ndb.StringProperty()
cost = ndb.FloatProperty()
type = ndb.StringProperty()

class SpecialProperty(ndb.Model):
name = ndb.StringProperty()
properties = ndb.StructuredProperty(Property, repeated=True)
type = ndb.StringProperty()

class Hotel(ndb.Model):
specialProperties = ndb.StructuredProperty(SpecialProperty, repeated=True)

但是当我尝试这个 GAE 时会抛出一个错误。“TypeError:此 StructuredProperty 无法使用 repeated=True,因为其模型类 (SpecialProperty) 包含重复属性(直接或间接)。”

那么我怎样才能绕过这个呢?我真的需要这种灵活的结构。

非常感谢。

最佳答案

Although a StructuredProperty can be repeated and a StructuredProperty can contain another StructuredProperty, beware: if one structured property contains another, only one of them can be repeated. A work-around is to use LocalStructuredProperty, which does not have this constraint (but does not allow queries on its property values).

https://developers.google.com/appengine/docs/python/ndb/properties#structured

使用 LocalStructuredProperty,您将拥有相同的结构,但您将无法按此属性进行过滤。如果您确实需要通过其中一个属性进行查询 - 尝试将其放入另一个实体中。

关于python - 另一个 StructuredProperty 中的 StructuredProperty。如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21605892/

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