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