insert default form value from controller

8 views
Skip to first unread message

stefaan

unread,
Dec 8, 2008, 4:31:06 PM12/8/08
to web2py Web Framework
Hello list,

A question about form default values:
I was hoping to do something like this in a controller:

form = t2.create(db.mytable)
form.a_field_in_my_table = "somecalculateddefaultvalue"
return dict(form = form)

Is this possible? And what would be the correct syntax for it ?

Best regards,
Stefaan.

stefaan

unread,
Dec 8, 2008, 4:35:37 PM12/8/08
to web2py Web Framework
Sorry, I just found http://groups.google.com/group/web2py/browse_thread/thread/ec1d5568db2598e6

Will try this out first!
Thanks

stefaan

unread,
Dec 8, 2008, 4:40:41 PM12/8/08
to web2py Web Framework
It works, but I'm still wondering if this construct is thread-safe ?
(I want to use it to automagically initialize a non-displayed field.)

mdipierro

unread,
Dec 8, 2008, 5:15:21 PM12/8/08
to web2py Web Framework


t2.create uses but differs from SQLFORM. You should use:

form = t2.create(db.mytable,vars={'a_field_in_my_table':'some
calculated value'})

OR

form = t2.create(db.mytable,vars=lambda
form:form.vars.a_field_in_my_table=some_calculated_value(form))

Massimo

stefaan

unread,
Dec 8, 2008, 5:31:56 PM12/8/08
to web2py Web Framework
Works like a charm. Thanks a lot!

notabene

unread,
Jan 8, 2009, 7:43:14 AM1/8/09
to web2py Web Framework
Dont work for me:
form=t2.create(db.arr,vars={'name':'Test'})

name is a string-field in db.arr

I use latest version of web2py and t2/t3
I don't understand??!


On 8 Dec. 2008, 23:15, mdipierro <mdipie...@cs.depaul.edu> wrote:
> t2.createuses but differs from SQLFORM. You should use:
>
> form =t2.create(db.mytable,vars={'a_field_in_my_table':'some
Reply all
Reply to author
Forward
0 new messages