Ok thanks for the help, much appreciated by newbie trying to learn 

On Tuesday, 3 November 2015 02:09:28 UTC+11, Niphlod wrote:
>
> it works but it's a rather inefficient way. first() and last() will need 
> to fetch every record of that table ............
>
> you'd better rewrite 
>
> task = db(db.stock_task.id).select().last()
>
> as
>
> task = db(db.stock_task.id>0).select(limitby=(0,1), orderby=~
> db.stock_task.id).first()
>
> etc etc etc
>
> to leverage the backend capabilities instead of fetching the entire table 
> and then discarding every row that is not the last one ...
>
> On Saturday, October 31, 2015 at 7:02:03 AM UTC+1, Anthony Smith wrote:
>>
>> Thanks for the input everyone , I did get it to successfully update using 
>> the following 
>>
>> def create_stock_task():
>>     form = SQLFORM (db.stock_task).process()
>>     if form.accepted:
>>         task = db(db.stock_task.id).select().last()
>>         pdays_row = db(db.product.withholding_period>0).select().last()
>>         pdays =  pdays_row.withholding_period
>>         esidays_row = db(db.product.ESI_withholding>0).select().last()
>>         esidays = esidays_row.ESI_withholding
>>         wdate_row = db(db.stock_task.completed_date>0).select().last()
>>         wdate = wdate_row.completed_date
>>         fdate = wdate + datetime.timedelta(days + pdays)
>>         esidate = wdate + datetime.timedelta(days + esidays)
>>         db(db.stock_task.id == task).update(withhold_until_date=fdate)
>>         db(db.stock_task.id == 
>> task).update(ESI_withhold_until_date=esidate)
>>
>> On Wednesday, 28 October 2015 18:00:05 UTC+11, Anthony Smith wrote:
>>>
>>> added the following
>>>
>>> def create_stock_task():
>>>     form = SQLFORM (db.stock_task).process()
>>>     if form.accepted:
>>>         task = db(db.stock_task.id).select().first()
>>>         pdays_row = db(db.product.withholding_period>0).select().first()
>>>         pdays =  pdays_row.withholding_period
>>>         wdate_row = db(db.stock_task.completed_date>0).select().first()
>>>         wdate = wdate_row.completed_date
>>>         fdate = wdate + datetime.timedelta(days + pdays)
>>>         ndate_row = 
>>> db(db.stock_task.withhold_until_date>0).select().first()
>>>         ndate = ndate_row.withhold_until_date
>>>         db(db.stock_task.id == task).update(ndate=fdate)
>>>         session.flash="New Task Added"
>>>         redirect(URL('stock_tasks'))
>>>     return locals()
>>>
>>>
>>>  and now getting <type 'exceptions.KeyError'>('ndate')
>>>
>>> further would be great 
>>>
>>> thanks.
>>>
>>> On Monday, 26 October 2015 20:09:15 UTC+11, Niphlod wrote:
>>>>
>>>> an update operation NEEDS an update() call.
>>>>
>>>> given the records you want to update are defined by a condition, namely
>>>>
>>>> db.table.column_1 == somevalue
>>>>
>>>> and the update on column_2 resulting in all those records equal to 
>>>> "somevalue_2", you need to write
>>>>
>>>> db(db.table.column_1 == somevalue).update(column_2 = somevalue_2)
>>>>
>>>>  
>>>>
>>>> On Saturday, October 24, 2015 at 7:27:20 AM UTC+2, Anthony Smith wrote:
>>>>>
>>>>> what I want to is update the stock_task.withhold until date with the 
>>>>> result of db.product.withholding_
>>>>> period (int) + stock_task.completed date (date)
>>>>>
>>>>>

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