Hi,
On a Smartgrid I want to define a filter for a linked_tables)field BUT
based on a query which is related to a table not part of the Smartgrid
definition.
I believe code speaks better than thousands words so, as follows :
...
db.define_table('*orden*',
Field('cliente', 'reference cliente'),
Field('numero','integer'),
migrate='orden.table',
format=lambda r: '%s->%s' % (r.numero, db.cliente[r.cliente].nombre )
)
db.define_table('*item_orden*',
Field('orden', 'reference orden'),
Field('paquete', 'reference paquete'),
Field('qty','double',label="Cantidad",notnull=True),
Field('precio_unitario','double',label="Precio Unitario",notnull=True),
migrate='item_orden.table',
format = '%(orden)s %(paquete)s %(id)s')
db.define_table('*movimiento_paquete*',# required to define which paquete
should appear on the form: those with a 'Apertura' occurrence
Field('paquete','reference *paquete*'),
Field('fecha','date',label="Fecha",notnull=True,default=request.now),
Field('evento',label="Evento",requires=IS_IN_SET(['Ingreso',
'Movimiento', 'Apertura', 'Cierre'])),
migrate='movimiento_paquete.table',
format = '%(paquete)s %(fecha)s %(evento)s'
)
...
def opened_package():
# criteria to filter
query = (db.paquete.id==db.movimiento_paquete.paquete) &
(db.movimiento_paquete.evento=='Apertura')
opened_set = db(query).select(db.paquete.ALL)
#ideally would be something like: constraints={'paquete':opened_set}
but *paquete* is not part of smartgrid definition, seems does not make
difference if is included or not
grid = SQLFORM.smartgrid(db.orden,linked_tables=['item_orden'],
user_signature=False,
constraints=constraints)
return dict(grid=grid)
--
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.