Thanks Anthony for your explanation of request.args use with smartgrid, I
tried your suggestion, but had the same error. I think i made a mistake in
the constraints in my earlier post (according to the documentation,
constraints is a dict of tablename:query), here is what i have changed.
invoice_grid = SQLFORM.smartgrid(db.invoice, args=request.args[:1],
constraints=dict(invoice=invoice_query),
linked_tables=dict(invoice=['item'], item=[]))
Noted that i could select a set of invoices based on the customer_id I
passed in through request.args(0), the only thing it broke was when I
clicked on the linked_tables "Items" with error Query Not Supported:
invalid literal for long() with base 10: 'item'.
I have been stuck here for a few days, any further help is much
appreciated.
On Thursday, March 30, 2017 at 12:33:07 PM UTC+8, Rudy wrote:
>
> Hi there,
>
> I am very new to web2py, i posted 1 question here a week ago, but never
> got reply (if anyone sees my post, please let me know if I missed
> anything), I am trying luck with another question now.
> I have a customer table, an invoice table and an item table. I simplified
> them below:
>
> db.define_table('customer', Field('company_name',
> requires=IS_NOT_EMPTY()), auth.signature, format='%(company_name)s')
> db.define_table('invoice', Field('customer', 'reference
> customer'), Field('project_name', requires=IS_NOT_EMPTY()))
> db.define_table('item', Field('invoice', 'reference invoice',
> writable=False), Field('description'), Field('unit_price', 'double'))
>
> When I used smartgrid without specifying the constraints below, the
> linked_tables 'Items' worked correctly (i.e. i clicked Items link, it
> showed me all the items belongs to that particular invoice), but obviously
> i could not select a particular set of invoices based on a customer id.
> when I added the constraints, i could select the particular invoices based
> on the given customer id, but the linked_tables 'Items' broke with this
> error message - Query Not Supported: invalid literal for long() with base
> 10: 'item'. The URL got redirected from
> http://localhost:8000/connect28/accounting/view_invoices/invoice/item.invoice/10?_signature=0653b123ba6f4b43b82c48d49516af9c772b1496
>
> to http://localhost:8000/connect28/accounting/view_invoices/item. Any
> help and pointers is much appreciated.
>
> def view_invoices():
> customer_id = request.args(0)
> if customer_id:
> invoice_query=db.invoice.customer==customer_id
> else:
> invoice_query=db.invoice.customer!=None
> constraints=dict(invoice=invoice_query)
> db.item.invoice.writable=False #avoid invoice # from any particular
> row in item table get overwritten
> invoice_grid = SQLFORM.smartgrid(db.invoice, constraints=constraints)
> return locals()
>
--
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.