The sorting via orderby is handled by the database, so you can't use Python 
code for that, as it must be executed by the database. However, the Rows 
object has a .sort() method, which does the sorting in Python after the 
records are returned by the database. See 
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#find--exclude--sort.

Note, depending on the size of the dataset, sorting in Python might be 
slower than having the database handle it.

Anthony

On Thursday, April 30, 2015 at 3:42:06 PM UTC-4, Ian W. Scott wrote:
>
> I want to sort the results of a select() based on a string field. Normally 
> I can just use select(orderby=db.mytable.myfield), but the strings are not 
> in Latin characters, so the default string sorting produces unacceptable 
> results. 
>
> I've figured out how to create a comparison function using the PyICU 
> bindings to the ICU library. In a regular list sort this allows me to do 
> something like this:
>
>     from icu import Locale, Collator
>     myloc = Locale('el')                                                
>     col = Collator.createInstance(myloc)                     
>     words = ['ἀγ', 'βλα', 'ὁμηρ']                                    
>     sorted_words = sorted(words, cmp=col.compare) 
>
> Is there any way to pass this kind of custom collating function to the 
> select()?   
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to