Reputation: 14519
There is no populate
method on StructuredProperty
(like the one on ndb.Model
) so how do I populate those fields from a dict?
Upvotes: 1
Views: 176
Reputation: 4963
You can still populate
the StructuredProperty
.
If you have models like this:
class A(ndb.Model):
value = ndb.IntegerProperty()
class B(ndb.Model):
name = ndb.StringProperty()
a = ndb.StructuredProperty(A)
The following will populate the properties of both:
my_dict = {"name":"my name", "a":{"value":1}}
b = B()
b.populate(**my_dict)
You can also call populate
on the property:
my_dict = {"value":1}
b = B()
b.a = A()
b.a.populate(**my_dict)
Note that what is returned by the getter is not the StructuredProperty
instance. It is an instance of A
. So calling populate
works.
Upvotes: 1