Sorting the request with ListProperty (NDB)

How do I sort the request using ListProperty *?

Model:

class Chapter(ndb.Model):
    title = ndb.StringProperty(required=True)
    version = ndb.IntegerProperty(repeated=True)

      

"version" stores values ​​such as:

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 this:

1
1.1
1.2
2.1.1.1.1
2.1.2

      

* Im using NDB, so ListProperty = ndb.IntegerProperty (repeat = True)

+3


source to share


2 answers


OMG I finally did it.

newChaps = sorted(chaps, key=lambda obj: obj.version)

      



So easy ... and so long to find it ...

+1


source


This is not how listproperties work. For an ascending order query, the value used will be the smallest in the list. You will need to store the values ​​in different ways (like a string) in order to do what you ask.



+2


source







All Articles