Way back when, I asked a similar question:
<URL:https://groups.google.com/d/topic/web2py/bnuall8tsgc/discussion>

I have a different application, where I want to order the rows according to 
a string field, where the string field has a prefix and a suffix, and the 
suffix is the dominant part of the ordering:

4321A < 0123B,
2345D < 5432D

etc

It's really easy to write a custom cmp() for this, and then to do sorted(rows, 
mycmp), but the result is a list, not a Rows object; in particular, it 
loses the colnames.  If  I do 
db(query1).select().sort(mycmp),
that fails because mycmp() requires 2 arguments, but 1 given.

The example of sort() in the book doesn't mind having only 1 argument:

The use of orderby='<random>' is not supported on Google NoSQL. However, in 
this situation and likewise in many others where built-ins are 
insufficient, imports can be used:

1
2

import randomrows=db(...).select().sort(lambda row: random.random())

<URL:http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#orderby--groupby--limitby--distinct--having-orderby_on_limitby-left-cache>

So how do I use sort() when the comparison requires 2 arguments?
(I'm using sqlite3 for this project, so I'm not ready to think about 
putting a procedure on the db server.)

Or if I use sorted(), how do I turn list back into a Rows object?  (Okay, 
there's a work-around for this ... write the view to handle a list, rather 
than having a default view, but one of these days I'm bound to need a Rows 
object.)

/dps

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