【发布时间】:2013-04-08 02:41:32
【问题描述】:
我有一个 GAE(谷歌应用引擎)应用程序,它每隔 15 分钟解析一次网站。每 15 分钟,cron 将检查要加载的最旧数据(在本例中为 BitData())的时间戳,并将从该点解析数据,直到 utc.now()。
不幸的是,我无法通过查询 NDB 数据库以获取最新的 BitData() 对象的第一部分。
代码示例:
def bitcoincharts_last():
q = BitData.query()
q = q.order(BitData.tstamp)
if q == None:
return '0'
else:
return q[0]
这会在日志中显示错误:
TypeError: order() expects a Property or query Order; received <class 'google.appengine.ext.ndb.model.DateTimeProperty'>
使用q = q.order(-BitData.tsamp) 来反转响应的顺序,而不是给出:
TypeError: bad operand type for unary -: 'type'
我已经对照示例 here、here 和 NDB Google Docs 检查了我的代码,但我似乎找不到查询无法运行的原因。
比特数据:
class BitData(ndb.Model):
key = ndb.KeyProperty
tstamp = ndb.DateTimeProperty
price = ndb.IntegerProperty
amount = ndb.IntegerProperty
【问题讨论】:
-
你BitData模型的定义是什么?
-
更新了问题。
标签: python google-app-engine app-engine-ndb