【发布时间】:2015-06-25 12:11:03
【问题描述】:
我有如下 NDB 模型类:
class Contest(ndb.Model):
end_date = ndb.DateProperty(required=True, indexed=True)
ended = ndb.BooleanProperty(required=False, indexed=True)
...
我将有一个每日 cron 作业来标记通过 end_date 和 ended 等于 True 的比赛。为此,我编写了以下代码:
contests = Contest.query()
current_datetime = datetime.datetime.utcnow()
today = datetime.date(current_datetime.year, current_datetime.month, current_datetime.day)
contests = contests.filter(Contest.end_date < today)
contests = contests.filter(Contest.ended == False)
contests = contests.fetch(limit=10)
for contest in contests:
contest.ended = True
ndb.put_multi(contests)
但我不喜欢它,因为我必须读取所有实体才能更新一个值。有什么办法可以修改为keys_only?
【问题讨论】:
标签: google-app-engine google-cloud-datastore app-engine-ndb