Hi all,
I am at a lose of how to update a table with the row count form another
table, I have been able to count and create a new form , which updates the
other table .
But I am hoping it is possible to be for the update to be automatic when
changes are made to the 1st table .
Below is a shorten version of the models and the controllers:
model/db1.py
db.define_table('stock',
Field('product'),,
Field('start_count','integer', default=0),
Field('count_now'))
db.define_table('stock_item',
Field('product', 'reference stock'),
Field('size'),
Field('color'),
Field('weight'))
controller/ default
def stocks():
db.stock.product.represent = lambda product,row:\
A(product,_href=URL('view_stock', args=row.id))
query = (db.stock.created_by.belongs(group_members))
grid = SQLFORM.grid(query, orderby=~db.stock.created_on,
create=False,details=False,editable=True,
deletable=False,
fields =[
db.stock.product,
db.stock.start_count,
db.stock.count_now,
])
return locals()
def stock_items():
db.stock_item.product.represent = lambda product,row:\
A(product,_href=URL('view_stock_item', args=row.id))
query = (db.stock_item.created_by.belongs(group_members))
grid = SQLFORM.grid(query, orderby=~db.stock_item.created_on,
create=False,details=False,editable=False,
deletable=False,
fields =[
db.stock_item.product,
db.stock_item.size,
db.stock_item.color,
db.stock_item.weight,
])
return locals()
This is the part I would like to run on update, there is no need for it to
output to a form just update the stock table.
def stockcount():
query =
db(db.stock_item._id>0).select(db.stock_item.product,db.stock_item.product.count(),orderby=db.stock_item.product,groupby=db.stock_item.product)
for row in query:
db.stock.update_or_insert(db.stock._id == row.stock_item.product,
count_now =
row[db.stock_item.product.count()])
form =SQLTABLE(query)
return dict(form=form)
thanks for any help and assistance
anthony
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.