Create a table for priority definitions, give them ids and labels... use represent on the priority field of the task table.
On Friday, March 14, 2014 4:53:27 PM UTC-7, Dan Why wrote: > > > I am building a TODO-list type application while studying web2py. For each > task, I would like to set a priority. Having integer values for priority > makes it easier to query something like db(db.task.priority > 1).select(). > Because there will be only a few of them, I would just create some > constants for them (rather than creating a priority table). Also I would > like to show descriptive text rather than numbers on drop-down list. > > My model looks something like this. > > class Priority: > LOW, MEDIUM, HIGH, URGENT = range(1, 5) > set = {LOW: 'Low', MEDIUM: 'Medium', HIGH: 'High', URGENT: 'Urgent'} > > db.define_table('task', Field('name'), Field('priority', > requires=IS_IN_SET(Priority.set, zero='Select on'))) > > Everything works well, except that on the view it is kind of ugly to > display the priority text instead of numbers. The way I am doing is > > <td>Priority: </td> <td>{{= Priority.set[ int( task.priority ) ] }}</td> > > I envision that it would become uglier and harder to understand, where I > start adding more fields. I wonder if there's a better way to do this? I am > also open to go about other ways than doing a constant based approach. > > Thanks a lot for your help! - Dan > -- 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.