[web2py] Re: IS_IN_DB orderby natural sort?

2013-05-13 Thread rppowell
Thank you Calvin; I had to do the following changes, changing 'items.sort(...)' to 'sorted(items,...)', but the drop down displays the item_typess in natural sort order: import re def natural_key(string_): return [int(s) if s.isdigit() else s for s in re.split(r'(\d+)', string_)] db.define_t

[web2py] Re: IS_IN_DB orderby natural sort?

2013-05-13 Thread Calvin
How about doing your own widget: import re def natural_key(string_): return [int(s) if s.isdigit() else s for s in re.split(r'(\d+)', string_)] items = db(db.item_type.id > 0).select() sorted_items= items.sort(key=natural_key(items.name)) db.item.item_type.widget = lambda f, v: SELECT([OPTION(

Re: [web2py] Re: IS_IN_DB orderby natural sort?

2013-05-13 Thread Johann Spies
In such cases I would use Type01, Type02 in stead of Type1, Type2 Regards Johann On 13 May 2013 02:07, rppowell wrote: > Here is example code to show what I am doing. > > The following is in model/db.py: > > db.define_table('item_type', > Field('name'), > Field('description'), > fo

[web2py] Re: IS_IN_DB orderby natural sort?

2013-05-12 Thread rppowell
Here is example code to show what I am doing. The following is in model/db.py: db.define_table('item_type', Field('name'), Field('description'), format='%(name)s' ) db.define_table('item', Field('name'), Field('description'), Field('item_type'), format='%(name)s' ) d

[web2py] Re: IS_IN_DB orderby natural sort?

2013-05-11 Thread Niphlod
IS_IN_DB accepts a "orderby" parameter. On Saturday, May 11, 2013 6:11:41 AM UTC+2, rppowell wrote: > > I have pre-populated a table of types by name: > db.item_type.insert(name='Type1'...) > db.item_type.insert(name='Type2'...) > db.item_type.insert(name='Type3'...) > ... > db.item