On Thursday, January 30, 2014 5:06:30 PM UTC-5, Ryan Matlock wrote:
>
> Now that I've spent a little more time implementing your answer, I've 
> noticed that the answers are sorted by id.  Is there any way to take the 
> table object and sort it?  I've already tried .sorted(), but as expected, 
> it didn't work.  This seems like the sort of thing you'd do in a 
> controller, so I can understand why you wouldn't be able to do this in 
> db.py.
>

By default, there is no explicit sorting -- the order is whatever the 
database returns (which will generally be ordered by id). To change the 
order, you'll have to specify the IS_IN_DB validator explicitly:

Field('manufacturer', 'reference test_manufacturer',
      requires=requires=IS_IN_DB(db, 'test_manufacturer.id', db.
test_manufacturer._format, sort=True))

That will sort alphabetically by the labels. You can also sort based on 
some field or fields in db.test_manufacturer by specifying the orderby 
argument:

Field('manufacturer', 'reference test_manufacturer',
      requires=requires=IS_IN_DB(db, 'test_manufacturer.id', db.
test_manufacturer._format,
                                 orderby=db.test_manufacturer.name))

Anthony

-- 
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/groups/opt_out.

Reply via email to