第一个模型
class A(db.Model):
number = db.IntgerProperty()
第二个模型
class B(db.Model):
name = db.StringProperty()
numbers = db.ListProperty(db.Key)
A
模型已成功保存。
a = A()
a.number = 90
a.put()
BadValueError:数字列表中的项目必须都是 Key 实例
b = B()
b.name = 'test'
b.numbers = [90]
b.put()
请帮忙吗?非常感谢。
最佳答案
编辑(基于OP评论):如果您想插入db.Key
,您需要提供一个。
调用 put()
返回一个键,因此您可以使用它,例如:
a = A()
the_key = a.put()
b = B()
b.name = 'test'
b.numbers = [the_key]
b.put()
<小时/>
OP澄清之前的旧答案:
使用 db.ListProperty(db.Key)
,您表示需要 db.Key
实例的列表。
如果您想要整数,请像这样声明您的模型:
class B(db.Model):
name = db.StringProperty()
numbers = db.ListProperty(int)
^^^
关于python - 如何使用ListProperty(数字列表中的项目必须都是Key实例),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9827201/