[英]repeated StructuredProperty of ndb.GeoPt
How do I repeat geo points as structured properties? 如何将地理位置重复为结构化属性?
My code looks like this: 我的代码如下所示:
class MyModel(EndpointsModel):
segments = ndb.StructuredProperty(ndb.GeoPt, repeated=True)
When I try to run the code and create instances of MyModel I get the following error: 当我尝试运行代码并创建MyModel实例时,出现以下错误:
AttributeError: type object 'GeoPt' has no attribute '_has_repeated'
How to find out if a model class is db or a ndb seems to suggest that _has_repeated is a property specific to ndb models, and https://cloud.google.com/appengine/docs/python/ndb/properties#structured seems to suggest that ndb.GeoPt is identical to db.GeoPt. 如何确定模型类是db还是ndb似乎暗示_has_repeated是特定于ndb模型的属性,而https://cloud.google.com/appengine/docs/python/ndb/properties#structured似乎建议ndb.GeoPt与db.GeoPt相同。
Why do you want to use GeoPt with structured property? 为什么要对结构化属性使用GeoPt? Just use something like this:
只需使用以下内容:
class MyModel(EndpointsModel):
segments = ndb.GeoPtProperty(repeated=True)
But if you want to store extra information with each GeoPt object, then use structured property like this: 但是,如果您想与每个GeoPt对象一起存储额外的信息,请使用以下结构化属性:
class GeoPtWithStruct(ndb.Model):
geo = ndb.GeoPtProperty()
bla = ndb.StringProperty()
class MyModel(EndpointsModel):
segments = ndb.StructuredProperty(GeoPtWithStruct, repeated=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.