I've been using SQLFORM.factory() for cases where what's in the db
needs to be presented to the user in a different format. The online
book has some good examples. For your case, my first thought would be
to define a function in the model that generates the form, e.g.
def fooform():
fields = []
...
fields.append('Feet', 'integer', ...)
fields.append('Inches', 'integer', requires=IS_IN_SET(range(0-12)))
fields.append('Fraction', 'string', requires=IS_IN_SET(["0", "1/4",
"1/2", "3/4"]))
...
return SQLFORM.factory(*fields)
Then in your controller,
form = fooform()
if form.accepts():
form = fooform()
if form.accepts():
On Jun 4, 12:09 pm, Keith <[email protected]> wrote:
> I'm new to web2py and the I did this previously was with javascript
> but I was hoping to avoid that this go around.
>
> In my database table I have a single field something like this below:
>
> db.define_table('foo',
> Field('height', 'double'),
>
> In the controller/view I need to be able to translate that so when
> viewing a record they see:
> Feet, Inches, and Fractions of a Inch.
>
> When adding a record it would need to be a text field for feet and
> drop down lists for inches and fractions of a inch.
>
> I know how to do that in javascript, but I don't like relying on
> javascript if possible. I'm hoping there is a way to do this in the
> controller or model.
>
> Thanks for any suggestions.