1

我有一个基础课:

class Post (db.Model):
    title = db.StringProperty(required = True)
    text = db.TextProperty(required = True)
    created = db.DateTimeProperty(auto_now_add = True).

new_record = Post(title = "TESSSST", text = "TESSST") 
new_record.put() #works!

它工作正常 - 创建实例并写入数据。但是一旦我删除“required = true”属性就不再存储在数据存储中:

class Post (db.Model):
    title = db.StringProperty(required = True)
    text = db.TextProperty  
    created = db.DateTimeProperty(auto_now_add = True)

new_record = Post(title = "TESSSST")
new_record.text = "Burn conctructor!"
new_record.put() # text property won't be saved

我不知道这是否有帮助,但是当我print new_record.__dict__通过构造函数分配的所有值检查属性时,都有'_'前缀(如'_title')而其他没有(只是'文本')。

所以问题是“是否可以将非必需(并且未由构造函数初始化)属性保存到数据存储区?” 我在 gae 文档中找不到答案。

4

1 回答 1

1

但是您不仅删除required=True了 ,还删除了()实例化该字段的括号。它应该是

text = db.TextProperty()
于 2012-09-05T08:43:48.707 回答