应用引擎将项附加到ListProperty

2024-10-01 13:40:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我想我疯了,为什么下面的工作不起作用?在

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()

我得到这个错误:

^{pr2}$

医生说:

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.

所以在我看来,我得到了默认值(一个空列表),并向它附加一个新值,然后保存它。在


Tags: thenonedefaultdbmodelispropertyindexed
2条回答

您应该删除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()

替换此项:

p.childrenKeys = p.childrenKeys.append('newchildkey')

有了这个:

^{pr2}$

append()返回None,它不能分配给p.childrenKeys。在

相关问题 更多 >