2013-04-08 46 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