这里是 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 暂时在马里廷巴克图市工作。我该如何检索和更新他的工作地址?
谢谢。
最佳答案
我会尝试这样的事情。
for address in guido.addresses:
if address.type == 'work':
address.street = "Main Street"
address.city = "Timbuktu"
guido.put()
编辑 添加了一个冒号
关于python - 如何检索和操作 ndb StructuredProperty 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12446132/