简体   繁体   中英

How to recognize that ndb query is sorted and how to reverse sort order without knowledge of sort order?

  1. How can I check if query is sorted?

    class Thing(ndb.Model): pass

    query = Thing.query().sort(Thing.id)

  2. How can I reverse such sort?

query.orders will return a datastore_query.Order , which has a reversed method, so something like:

query = Thing.query().order(Thing.id)
[...]
order = query.orders
reversed_order = order.reversed()
new_query = Thing.query().order(reversed_order)

If there isn't an order on the query, order will be None

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM