How do i sort a query by a ListProperty*?
the Model:
class Chapter(ndb.Model):
title = ndb.StringProperty(required=True)
version = ndb.IntegerProperty(repeated=True)
the 'version' stores values like:
1.1 -> [1,1]
1 -> [1]
2.1.1.1.1 -> [2,1,1,1,1]
1.2 -> [1,2]
2.1.2 -> [2,1,2]
I want to order it like:
1
1.1
1.2
2.1.1.1.1
2.1.2
*Im using NDB so, ListProperty = ndb.IntegerProperty(repeated=True)
That's not how listproperties work, unfortunately. For an ascending-order query, the value used will be the smallest in the list. You'll have to store the values differently (as a string, for example) to do what you're asking.
OMG I finally did it.
newChaps = sorted(chaps, key=lambda obj: obj.version)
So simple... and yet so much time to find it...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With