On 29 February 2012 13:35, Roderick <[email protected]> wrote:
> Hi web2py users!
>
> 1. Can anyone tell me if the query input field on SQLform smartgrid
> forms can do a join on 2 or more tables?
>
If you use SQLFORM.grid the answer is 'Yes'
> 2. If so, how do I construct such a query? My attempts my failed and
> can't find docs on this either...
>
>
Here is a small example:
query = ((db.akb_doccenter.location == db.akb_doccenter_location.uuid)&
(db.akb_doccenter.category == db.akb_doccenter_category.uuid))
Fields = [db.akb_doccenter.title, db.akb_doccenter.author,
db.akb_doccenter.publication_date,
db.akb_doccenter.doc_nr, db.akb_doccenter_location.location,
db.akb_doccenter_category.category]
fields = columns
opskrif = H2(T('Document Center Contents'))
links = [lambda row: A('Edit' , _href = URL('doccenter', 'akb_docedit',
args = [row.id]))]
if auth.is_logged_in() and auth.has_membership('doccenter', auth.user.id
):
data = SQLFORM.grid(query, fields = fields,
orderby = db.akb_doccenter.title |
db.akb_doccenter.publication_date,
#links = links, editable = False,
maxtextlength = 60)
else:
data = SQLFORM.grid(query, fields = fields, orderby =
db.akb_doccenter.title | db.akb_doccenter.publication_date,
deletable = False, editable = False, maxtextlength =
60)
> Note - I would like users to be able to construct and type in their
> own queries directly in the smartgrid query field. As these queries
> will be dynamic, doing this programmatically will be difficult - if
> the query can handle joins or fields from multiple tables then this
> should be "pie" :)
>
> Thanks!
--
Because experiencing your loyal love is better than life itself,
my lips will praise you. (Psalm 63:3)