以下是StructuredProperty from the docs的示例:
class Address(ndb.Model):
type = ndb.StringProperty() # E.g., 'home', 'work'
street = ndb.StringProperty()
city = ndb.StringProperty()
class Contact(ndb.Model):
name = ndb.StringProperty()
addresses = ndb.StructuredProperty(Address, repeated=True)
guido = Contact(name='Guido',
addresses=[Address(type='home',
city='Amsterdam'),
Address(type='work',
street='Spear St',
city='SF')])
guido.put()
想象一下,Guido暂时在马里的廷巴克图市工作。我如何才能检索和更新他的工作地址?
感谢。
答案 0 :(得分:3)
我会尝试这样的事情。
for address in guido.addresses:
if address.type == 'work':
address.street = "Main Street"
address.city = "Timbuktu"
guido.put()
修改强> 添加了一个冒号