gpt4 book ai didi

python - ndb.GeoPt 的重复结构化属性

转载 作者:行者123 更新时间:2023-12-01 04:59:41 24 4
gpt4 key购买 nike

如何将地理点重复作为结构化属性?

我的代码如下所示:

class MyModel(EndpointsModel):
segments = ndb.StructuredProperty(ndb.GeoPt, repeated=True)

当我尝试运行代码并创建 MyModel 实例时,出现以下错误:

AttributeError:类型对象“GeoPt”没有属性“_has_repeated”

How to find out if a model class is db or a ndb似乎表明 _has_repeated 是特定于 ndb 模型的属性,并且 https://cloud.google.com/appengine/docs/python/ndb/properties#structured 似乎表明 ndb.GeoPt 与 db.GeoPt 相同。

最佳答案

为什么要使用具有结构化属性的 GeoPt?只需使用这样的东西:

class MyModel(EndpointsModel):
segments = ndb.GeoPtProperty(repeated=True)

但是,如果您想为每个 GeoPt 对象存储额外信息,请使用如下结构化属性:

class GeoPtWithStruct(ndb.Model):
geo = ndb.GeoPtProperty()
bla = ndb.StringProperty()

class MyModel(EndpointsModel):
segments = ndb.StructuredProperty(GeoPtWithStruct, repeated=True)

关于python - ndb.GeoPt 的重复结构化属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26542715/

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