简体   繁体   中英

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:

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.

Why do you want to use GeoPt with structured property? 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:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM