2013-04-08 55 views
0

我有一个GAE(谷歌应用程序引擎)应用程序,它以15分钟的时间间隔解析一个网站。每隔15分钟cron将检查最旧数据的时间戳(在这种情况下为BitData()),并将解析来自该点的数据,直到utc.now()。 不幸的是,我无法通过查询NDB数据库的最新BitData()对象的第一部分。在cronjob中执行NDB查询

代码示例:

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' 

我已经用示例herehere检查我的代码, d NDB谷歌文档,但我似乎无法找到为什么查询不会运行。

BitData:

class BitData(ndb.Model): 
    key = ndb.KeyProperty 
    tstamp = ndb.DateTimeProperty 
    price = ndb.IntegerProperty 
    amount = ndb.IntegerProperty 
+1

什么是你的BitData模型的定义? – 2013-04-08 04:10:27

+0

更新了问题。 – Davidrd91 2013-04-08 04:35:25

回答

3

模型的定义应该是:

class BitData(ndb.Model): 
    key = ndb.KeyProperty() 
    tstamp = ndb.DateTimeProperty() 
    price = ndb.IntegerProperty() 
    amount = ndb.IntegerProperty() 

你只是定义你的类领域向NDB性能等级点,你实际上并没有实例任何人。

+0

谢谢你的工作。当我从常规数据库模型中切换时,我一定错过了。在命令之前也使用了这样的减号:'q = q.order(-BitData.tsamp)'仍然给出相同的错误 – Davidrd91 2013-04-08 05:16:51

+0

你确定吗?一旦您使用我提供的新模型定义,就可以正常工作。 – someone1 2013-04-08 05:27:10

+0

其实你的权利。在刷新之前,我可能没有将它保存在Eclipse中,然后再次更改它。非常感谢你! – Davidrd91 2013-04-08 05:35:46