我可能存储了数千个“报告”模型。我正在尝试获取DateTimeProperty订购的50个最新报告。尽管我现有的查询确实按从新到旧的顺序获取报告,但它不会返回最新的50。而是会返回较旧的(排序的)选择。我在这里想念什么?
class Report(ndb.polymodel.PolyModel):
received_time = ndb.DateTimeProperty(required=True, auto_now_add=True)
report_state = ndb.StringProperty(choices=set(['unresolved', 'resolved']))
...
reports_query = Report.query(
Report.report_state == 'resolved',
ancestor = some_key) \
.order(Report.received_time)
resolved_reports = reports_query.fetch(50)
在测试时,如果我的数据存储区中有200个报告并且获取了200个报告,那么我将按照正确的顺序对所有报告进行排序。
您的查询按的升序排序received_time
,因此查询时间更早(时间越短=时间越早)。要获取最早的,请更改顺序:
.order(-Report.received_time)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句