我有一个ComputedProperty
内部 aStructuredProperty
在首次创建对象时不会更新。
当我创建对象时address_components_ascii
没有保存。该字段在数据存储查看器中根本不可见。但是,如果我get()
然后立即put()
再次(即使没有更改任何内容),ComputedProperty
则按预期工作。该address_components
字段正常工作。
我曾尝试清除数据库,并删除整个数据库文件夹,但没有成功。
我在 Windows 7 上使用本地开发服务器。我尚未在 GAE 上对其进行测试。
这是代码:
class Item(ndb.Model):
location = ndb.StructuredProperty(Location)
内部位置类:
class Location(ndb.Model):
address_components = ndb.StringProperty(repeated=True) # array of names of parent areas, from smallest to largest
address_components_ascii = ndb.ComputedProperty(lambda self: [normalize(part) for part in self.address_components], repeated=True)
归一化函数
def normalize(s):
return unicodedata.normalize('NFKD', s.decode("utf-8").lower()).encode('ASCII', 'ignore')
字段示例address_components
:
[u'114B', u'Drottninggatan', u'Norrmalm', u'Stockholm', u'Stockholm', u'Stockholms l\xe4n', u'Sverige']
和address_components_ascii
字段,在第二个之后put()
:
[u'114b', u'drottninggatan', u'norrmalm', u'stockholm', u'stockholm', u'stockholms lan', u'sverige']