https://cloud.google.com/appengine/docs/python/ndb/properties#structured
In order to write entities with structured properties, I tried to read them first, to figure out the format.
First StructuredProperty.
classItem_Meta(ndb.Model):
xy=ndb.IntegerProperty(repeated=True)
classItem(ndb.Model):
meta=ndb.StructuredProperty(Item_Meta)
item=Item()
item.meta=Item_Meta(xy= [100, 200])
item.put() # 5710239819104256
>>>datastore.api.get([datastore.Key('Item', 5710239819104256)])
[<Entity[{'kind': u'Item', 'id': 5710239819104256L}] {u'meta.xy': [100L, 200L]}>]Next LocalStructuredProperty.
Although a StructuredProperty can be repeated and a StructuredProperty can contain another StructuredProperty, beware: if one structured property contains another, only one of them can be repeated. A work-around is to use LocalStructuredProperty, which does not have this constraint.
classItem_Meta(ndb.Model):
xy=ndb.IntegerProperty(repeated=True)
classItem(ndb.Model):
meta=ndb.LocalStructuredProperty(Item_Meta, repeated=True)
item=Item()
item.meta= [Item_Meta(xy= [100, 200])]
item.put() # 6217263929622528
>>>datastore.api.get([datastore.Key('Item', 6217263929622528)])
Traceback (mostrecentcalllast):
File"<stdin>", line1, in<module>File"/home/user/.local/lib/python2.7/site-packages/gcloud/datastore/api.py", line229, ingetentities.append(helpers.entity_from_protobuf(entity_pb))
File"/home/user/.local/lib/python2.7/site-packages/gcloud/datastore/helpers.py", line53, inentity_from_protobufvalue=_get_value_from_property_pb(property_pb)
File"/home/user/.local/lib/python2.7/site-packages/gcloud/datastore/helpers.py", line237, in_get_value_from_property_pbreturn_get_value_from_value_pb(property_pb.value)
File"/home/user/.local/lib/python2.7/site-packages/gcloud/datastore/helpers.py", line217, in_get_value_from_value_pbresult= [_get_value_from_value_pb(x) forxinvalue_pb.list_value]
File"/home/user/.local/lib/python2.7/site-packages/gcloud/datastore/helpers.py", line214, in_get_value_from_value_pbresult=entity_from_protobuf(value_pb.entity_value)
File"/home/user/.local/lib/python2.7/site-packages/gcloud/datastore/helpers.py", line48, inentity_from_protobufkey=key_from_protobuf(pb.key)
File"/home/user/.local/lib/python2.7/site-packages/gcloud/datastore/helpers.py", line105, inkey_from_protobufreturnKey(*path_args, namespace=namespace, dataset_id=dataset_id)
File"/home/user/.local/lib/python2.7/site-packages/gcloud/datastore/key.py", line76, in__init__self._path=self._combine_args()
File"/home/user/.local/lib/python2.7/site-packages/gcloud/datastore/key.py", line133, in_combine_argschild_path=self._parse_path(self._flat_path)
File"/home/user/.local/lib/python2.7/site-packages/gcloud/datastore/key.py", line94, in_parse_pathraiseValueError('Key path must not be empty.')
ValueError: Keypathmustnotbeempty.
https://cloud.google.com/appengine/docs/python/ndb/properties#structured
In order to write entities with structured properties, I tried to read them first, to figure out the format.
First
StructuredProperty.Next
LocalStructuredProperty.