在Python(GAE)中,如何使用追加在以下数据结构中设置“a”的值:
class Y(ndb.Model):
name = ndb.StringProperty()
hobby = ndb.StringProperty()
class X(ndb.Model):
a = ndb.StructuredProperty(Y, repeated=True)
使用下面的表单不起作用(在“数据存储查看器”中没有任何内容存储为已验证):
new_user_record = X()
new_user_record.a.append({'name':"john", 'hobby':"painting"})
new_user_record.put()
我做错了吗?什么是正确的方法?
答案 0 :(得分:2)
class X(ndb.Model):
a = ndb.StringProperty()
class Y(ndb.Model):
b = ndd.StructuredProperty(X,repeated=True)
x = Y()
x.b = [X(a="123"),X(a="abc")]
test> x
Y(b=[X(a='123'), X(a='abc')])
并附加
test> x.b.append(X(a='xxx'))
test> x.b
[X(a='123'), X(a='abc'), X(a='xxx')]
查看文档,它确实显示了您 - https://developers.google.com/appengine/docs/python/ndb/properties#structured