For n2, you could try only updating if n2 was not empty.  This is not 
tested but something like ...

Field('n2', 'integer', compute=lambda r: r.start_number if not r.n2 else 
None)


On Sunday, July 10, 2016 at 4:38:33 PM UTC-4, ahz...@gmail.com wrote:
>
> In my application a user enters a boolean value, and later the user can 
> modify the value*.* I want to save the original value in another field, 
> and the user shouldn't be able to see or alter the original value.
>
> Based on the stackoverflow 
> <http://stackoverflow.com/questions/16280220/setting-the-default-of-a-database-field-to-the-value-of-another-field-in-web2py>
>  
> conversation I tried a simple table with two  methods
> db.define_table('mytable',
>     Field('start_number', 'integer', requires=IS_NOT_EMPTY()),
>     Field('n1', 'integer', default=request.post_vars.start_number),
>     Field('n2', 'integer', compute=lambda r: r.start_number)
>     )
>
>
>
> Then I used the database administration to insert a value of 5, but *n1 *had 
> a value of zero (instead of 5).
>
> While *n2 *started with the value of 5, whenever I modified *start_number*, 
> it also modified *n2*.
>
> By the way, I wish I had web2py in 2003 when I started a bigger web 
> application.
>

-- 
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.

Reply via email to