0

I've read the documentation on how to do this but it is not working. I am trying to get my query to sort by date newest first, but this is not working:

wrQuery = WorkRequest.query()
wrQuery.order('-date')
wrResult = wrQuery.fetch()

I have also tried ('-WorkRequest.date') but both results in similar errors:

TypeError: order() expects a Property or query Order; received '-date'

jb2003
  • 123
  • 1
  • 11

2 Answers2

1

The query objects are immutable, your 3rd statement references the object from your 1st statement, not the ordered one created in the 2nd statement. See also NDB Query builder doesn't work as expected.

This should work instead:

 wrQuery = WorkRequest.query()
 wrOrderedQuery = wrQuery.order('-WorkRequest.date')
 wrResult = wrOrderedQuery.fetch()
Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
0

This looks like you are using NDB rather than DataStore, in which case the docs show you unequivocally how to do it. This should work:

wrQuery = wrQuery.order(-WorkRequest.date)
ChrisC73
  • 1,833
  • 14
  • 14