Wouldn't this be misleading because the computed field depends on the value of fields that may have been edited?
On Jan 8, 12:25 pm, howesc <[email protected]> wrote: > Let's say i have a table like: > > db.define_table('item_quantity', > Field('item', db.item, > requires=IS_IN_DB(db, db.item.id,'%(name)s'), > represent=lambda x: x.name), > Field('quantity', 'double', notnull=True, default=0.0, > comment="in ounces"), > Field('name', length=500, notnull=True, unique=True, > requires=IS_NOT_IN_DB(db, 'item_quantity.name'), > compute=lambda r: str(db.item[r.item].name) + ': ' + str(r.quantity) > +" oz"), > format='%(name)s', > migrate=migrate) > > if I do: > form = SQLFORM(db[request.args[0]], id) > the computed field is not shown at all. when i'm editing a row it would be > nice to see what the current value of the computed field is, as a read-only > field. > > i learned that i can do this: > #make compute fields read-only in the forms > for f in db[request.args[0]]: > if f.compute: > f.writable=False > #include all fields, include compute fields, in the forms > fields = [f.name for f in db[request.args[0]] if (f.writable or > f.readable)] > form = SQLFORM(db[request.args[0]], id, fields=fields) > > to achieve this behavior. Would it be bad to add an option to SQLFORM to do > this automagically? > > thanks, > > christian

