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_type.insert(name='Type10'...)
> db.item_type.insert(name='Type11'...)
> ...
>
> I want to use the table as selection in another table, (using
> requires=IS_IN_DB(db, db.item_type, '%(name)s'):
> db.define_table('item',
> Field('item_type', db.item_type),
> )
> db.item.item_type.requires = IS_IN_DB(db, db.item_type, '%(name)s')
>
> When I use a form to add a new record, the items are displayed out of
> order in the dropdown:
> Type1
> Type10
> Type11
> ...
> Type2
>
> How do I specify using natural sorting, for example, using the following
> python:
>
> import re
> def natural_key(string_):
> return [int(s) if s.isdigit() else s for s in re.split(r'(\d+)',
> string_)]
>
> items = [
> 'Item99', 'Item1', 'Item10', 'Item20', 'Item2', 'Item3', 'Item30'
> ]
> items.sort(key=natural_key)
> print ' '.join(items)
>
>
>
> How do I do this with the db in web2py? Do a query, sort the list, and
> use it as a IS_IN_SET()?
>
> -rppowell
>
--
---
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.