2
我需要檢索添加到集合中的最近項目。這是我如何做到這一點:獲取最新數據項 - Google App Engine - Python
class Box(db.Model):
ID = db.IntegerProperty()
class Item(db.Model):
box = db.ReferenceProperty(Action, collection_name='items')
date = db.DateTimeProperty(auto_now_add=True)
#get most recent item
lastItem = box.items.order('-date')[0]
這是一個昂貴的方式來做到這一點?有沒有更好的辦法?
完美。我爲Box添加了一個lastItem屬性,每次向Box添加項目時都會更新它。那好多了。謝謝。 – Eric 2010-10-21 00:58:17