Getting The Most Recent Data Item - Google App Engine - Python
问题 I need to retrieve the most recent item added to a collection. Here is how I'm doing it: 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] Is this an expensive way to do it? Is there a better way? 回答1: If you are going to iterate over a list of boxes, that is a very bad way to do it. You will run an additional