![](/img/trans.png)
[英]How to serialize ndb.GeoPt for JSON response to fit my needs in Python/Google App Engine
[英]repeated StructuredProperty of ndb.GeoPt
如何将地理位置重复为结构化属性?
我的代码如下所示:
class MyModel(EndpointsModel):
segments = ndb.StructuredProperty(ndb.GeoPt, repeated=True)
当我尝试运行代码并创建MyModel实例时,出现以下错误:
AttributeError: type object 'GeoPt' has no attribute '_has_repeated'
如何确定模型类是db还是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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.