+1 but only if var has a default=0 condition.
If not - not tested - 
 
db(db.table.id == 1).update(var = db.table.var.coalesce_zero() + 1)

should do the trick.

Il giorno giovedì 6 giugno 2013 09:30:37 UTC+2, Marin Pranjić ha scritto:
>
> Try this:
>
> db(db.table.id == 1).update(var = db.table.var + 1)
>
> Marin
>
>
> On Thu, Jun 6, 2013 at 9:12 AM, Robin Manoli <rama...@gmail.com<javascript:>
> > wrote:
>
>> I wonder about the most convenient way to increase an integer value, or 
>> append to a varchar. Is it possible in python to assign operators, such as:
>> *db.table.var(1) += 1 # increase the value of row 1 of table with 1*
>>
>> Otherwise, web2py could have an increase method for integer columns, and 
>> append for varchar/text columns.
>>
>> My function to do the former, (not tested yet):
>>
>> *incr_table_obj_val( table_obj, column, incr=1 ):*
>> *    value = getattr(table_obj, **column**)*
>>  *    if not **value **: **value **= 0*
>> *    **value **+= int(**incr**)*
>> *    table_obj.update_record(**{**column:**value**})*
>>
>>
>> What is your best way?
>>
>> -- 
>>  
>> --- 
>> 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+un...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 

--- 
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/groups/opt_out.


Reply via email to