簡體   English   中英

ndb.GeoPt的重復StructuredProperty

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM