【发布时间】:2015-10-02 18:52:12
【问题描述】:
我有一个已经存在的相当简单的 ndb 模型,并在数据存储区中创建了实例。它看起来像这样:
class ExampleModel(ndb.Model):
property1 = ndb.StringProperty()
property2 = ndb.StringProperty()
我想给它添加一个created 属性,这样我就可以在它们被创建时对它们进行排序。
class ExampleModel(ndb.Model):
property1 = ndb.StringProperty()
property2 = ndb.StringProperty()
created = ndb.DateTimeProperty(auto_now_add=True)
当我这样做并尝试查询由created 排序的实体列表时,它只返回更新模型定义后创建的实体。
things = ExampleModel.query().order(ExampleModel.created).fetch()
我尝试将默认值添加到created,设置为我希望现有实体出现在有序列表中的纪元,但它们仍然不包含在该有序查询中。有什么方法可以包含它们,还是我需要迁移现有实体并明确设置其created 属性?
【问题讨论】:
标签: python google-app-engine google-cloud-datastore app-engine-ndb