On Saturday, January 14, 2012 3:00:06 PM UTC-5, Alan Etkin wrote:
>
> I found with this code that the form created does not show in the
> browser:
>
> # controller
> ...
> # there is only one table defined with one (plus the id) field called
> myfield
> db.mytable.myfield.compute = lambda r: str(r.myfield) + "more text"
>
I believe a value will only be computed when no value is explicitly
inserted/updated, so upon record insertion, the above computation won't
happen if a 'myfield' value is passed in.
>
> # there is a record in db.mytable with id value 1 and myfield value
> None
> form = crud.read(db.mytable, 1)
> ...
>
> # view code
> {{ =form }}
>
I believe computed fields are automatically excluded from SQLFORMs unless
they are explicitly listed in the 'fields' argument. Unfortunately, I don't
think there is a way to specify the 'fields' argument with crud.read().
Maybe we should display computed fields in readonly forms by default, and
make it easier to included computed fields in create/update forms as well.
Anthony