How to orderby translation name?

21 views
Skip to first unread message

Francisco Costa

unread,
Dec 18, 2013, 12:29:40 PM12/18/13
to web...@googlegroups.com
I have this form for creating new items and where I ask for the colors that are referenced by an id saved in db.colors
I'm already showing the translated color names, but they are being ordered by the "original name"

I have this:

db.items.color.requires = IS_IN_DB(db, db.colors.id, lambda row: T(row.name), error_message=T('invalid color'), zero=T('---select---'), orderby=db.colors.name)

How can you sort colors by the translation name?

Leonel Câmara

unread,
Dec 18, 2013, 12:52:15 PM12/18/13
to
You have to either sort using javascript on the view or sort in the controller using something like

colors = db(db.colors.id > 0).select()
colors = colors.sort(lambda r : T(r.name, lazy=False))

Francisco Costa

unread,
Dec 18, 2013, 1:21:01 PM12/18/13
to web...@googlegroups.com
Thanks Leonel

because I'm using SQLFORM to generate the form I used a javascript solution, here is the code: http://stackoverflow.com/a/20665508/621727

Francisco Costa


On Wed, Dec 18, 2013 at 5:51 PM, Leonel Câmara <leonel...@gmail.com> wrote:
You have to either sort using javascript on the view or translate in the controller using something like

colors = db(db.colors.id > 0).select()
colors = colors.sort(lambda r : T(r.name, lazy=False))

--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/XTGXkxPn3kg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages