db.search_form.pet_type_ref.requires = 
IS_IN_DB(db,'pet_type',orderby=db.pet_type.description)

OR this may work too:

db.search_form.pet_type_ref.requires.orderby = db.pet_type.description 

On Thursday, 24 April 2014 07:31:40 UTC-5, M Bailey wrote:
>
> I'm trying to migrate a django project to web2py. I have defined a search 
> form with <select><option> fields populated from the database and using 
> code similar to below, but I can't see a way of changing the ordering of 
> the SQLFORM fields:
>
> db.define_table('pet_type',
>     Field('description', 'string', required=True, notnull=True, length=75),
>     format = '%(description)s')
>
> db.define_table('colour_type',
>     Field('description', 'string', required=True, notnull=True, length=75),
>     format = '%(description)s')
>
>
> db.define_table('search_form',
>     Field('pet_type_ref', 'reference pet_type', label='Pet'),
>     Field('colour_type_ref', 'reference colour_type', label='Pet colour'))
>
> In index controller:
> form = SQLFORM(db.search_form)
> return dict(form=form)
>
> In the view:
> {{=form}}
>
>
> In the admin section, I add some pets into the pet_type table but not in 
> alphabetical order, e.g. Dog, Budgie, Cat
>
> All works brilliantly in the view with <select> controls being used for 
> the reference fields. 
>
> However I can't see a way of changing the ordering of the pets for the 
> select. Currently it defaults to pet_type.description ASC but how would I 
> change it to the pet_type.id so that the records are displayed in the 
> order they are inserted?
>
> Thanks for any advice
> Mark
>
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to