オブジェクトが最初に作成されたときに更新されないComputedProperty
内部に aがあります。StructuredProperty
オブジェクトを作成してaddress_components_ascii
も保存されません。このフィールドは、Datastore Viewer にはまったく表示されません。しかし、私がget()
すぐput()
に(何も変更しなくても)再び実行するとComputedProperty
、期待どおりに動作します。address_components
フィールドは正常に動作します。
データベースをクリアし、データベース フォルダ全体を削除しようとしましたが、成功しませんでした。
Windows 7 でローカル開発サーバーを使用しています。GAE でテストしていません。
コードは次のとおりです。
class Item(ndb.Model):
location = ndb.StructuredProperty(Location)
内側の 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
フィールド、2 番目の後にput()
:
[u'114b', u'drottninggatan', u'norrmalm', u'stockholm', u'stockholm', u'stockholms lan', u'sverige']