I think I'm loosing my mind, why doens't the following work?
我想我已经失去了理智,为什么不做以下工作呢?
class Parent(db.Model):
childrenKeys = db.ListProperty(str,indexed=False,default=None)
p = Parent.get_or_insert(key_name='somekey')
p.childrenKeys = p.childrenKeys.append('newchildkey')
p.put()
I get this error:
我收到此错误:
BadValueError: Property childrenKeys is required
The doc says:
医生说:
default is the default value for the list property. If None, the default is an empty list. A list property can define a custom validator to disallow the empty list.
default是list属性的默认值。如果为None,则默认为空列表。 list属性可以定义自定义验证器以禁止空列表。
So the way I see it, I'm getting the default (an empty list) and appending a new value to it and the saving it.
所以我看到它的方式,我得到默认值(一个空列表)并为其添加一个新值并保存它。
2 个解决方案
#1
8
You should remove the p.childrenKeys
assignment:
您应该删除p.childrenKeys分配:
class Parent(db.Model):
childrenKeys = db.ListProperty(str,indexed=False,default=[])
p = Parent.get_or_insert('somekey')
p.childrenKeys.append('newchkey')
p.put()
#2
5
Replace this:
p.childrenKeys = p.childrenKeys.append('newchildkey')
with this:
p.childrenKeys.append('newchildkey')
append()
returns None
, which can't be assigned to p.childrenKeys
.
append()返回None,无法分配给p.childrenKeys。
#1
8
You should remove the p.childrenKeys
assignment:
您应该删除p.childrenKeys分配:
class Parent(db.Model):
childrenKeys = db.ListProperty(str,indexed=False,default=[])
p = Parent.get_or_insert('somekey')
p.childrenKeys.append('newchkey')
p.put()
#2
5
Replace this:
p.childrenKeys = p.childrenKeys.append('newchildkey')
with this:
p.childrenKeys.append('newchildkey')
append()
returns None
, which can't be assigned to p.childrenKeys
.
append()返回None,无法分配给p.childrenKeys。