Omair Shamshir
Omair Shamshir

Reputation: 2136

Google App Engine order by a property

I am writing a query which involves inequality filter.

query = my_model.all().filter('my_date <', given_date)

I want to sort the results by some other property. The problem is according to documentation i have to order the results by the inequality property first.

Does anyone know how can i sort my results by some other property.

Upvotes: 0

Views: 58

Answers (2)

Tim Hoffman
Tim Hoffman

Reputation: 12986

No, that documentation is correct.

You could sort the result set in memory.

You would have to provide more information about the other attributes. It might be possible to provide a single aggregate property that suits sort and the filter.

Upvotes: 1

fredrik
fredrik

Reputation: 17617

There's always the "after-fetch-sort". It may result in an incorrect list (since some entities might not been fetched).

query = my_model.all().filter('my_date <', given_date).fetch()
query.sort(key=lambda x: x.my_sort_property)

Can't remember but NDB might let you order + filter, but don't think so. Check it out, it's still much better then the old datastore API.

Upvotes: 2

Related Questions