Having the same problem, thank you for the info. The problem for me is that
I can get either the left join to work using row.table_name.field_name, or
the simple view to work by using row.field_name. Is there anyway to define
a represent-function to work with both?
On Tuesday, January 15, 2013 4:44:15 PM UTC+1, Sebastien Stormacq wrote:
>
> OK, using a debugger, I found out my problem.
>
> When doing a left join, the "row" variable does not contain directly the
> fields. We must use row.table_name.field_name instead.
>
> This is now working. Problem solved.
>
> Seb
>
> On Tuesday, January 15, 2013 4:13:45 PM UTC+1, Sebastien Stormacq wrote:
>>
>> Dear All,
>>
>> In one of my views, I am using a SQLForm.grid object. The grid is fed
>> with a table that has two computed fields and the query needs a LEFT JOIN
>> to another table.
>> The grid also use 'Links' to compute a field (create an column with an
>> IMG element depending on a column's value)
>>
>> Everything is OK, except when I mix computed fields and left join.
>>
>> Left join alone is OK
>> Computed field alone is OK
>>
>> Here is my model
>>
>> db('message',
>>
>> Field('address', 'text'),
>>
>> Field('date', 'datetime', required=True),
>>
>> Field('flags', 'integer'),
>>
>> Field('msgaccount', 'text'),
>>
>> Field('msgflags', 'integer'),
>>
>> Field('msghandle', 'text'),
>>
>> Field('ismsg', 'integer'),
>>
>> Field('text', 'text', required=True),
>>
>> Field('cfrom', 'text', compute=lambda r: computeCFrom(r)),
>>
>> Field('cflags', 'integer', compute=lambda r: computeCFlags(r)))
>>
>> Here is my grid
>>
>> grid = SQLFORM.grid(dbMsg.message,
>>
>> fields=[dbMsg.message.address,
>> dbMsg.message.date, dbMsg.message.flags,
>>
>> dbMsg.message.msgaccount,
>> dbMsg.message.msgflags,
>>
>> dbMsg.message.msghandle,
>> dbMsg.message.ismsg, dbMsg.message.text,
>>
>> dbMsg.message.cfrom,
>> dbMsg.message.cflags,dbMsg.address.description ],
>>
>> field_id=dbMsg.message.id,
>>
>>
>> #left=dbMsg.address.on(dbMsg.message.cfrom==dbMsg.address.address),
>>
>> orderby=~dbMsg.message.date,
>>
>> maxtextlengths={'message.date':5,
>> 'message.cfrom':20, 'address.description':20, 'message.text':160},
>>
>> headers={'message.cfrom' : T('From')},
>>
>> editable=False,
>>
>> create=False,
>>
>> details=False,
>>
>> deletable=False,
>>
>> csv=False,
>>
>> selectable=lambda ids: delete(ids),
>>
>> selectable_text=T('Delete'),
>>
>> links=[dict(header=T('Flags'), body=lambdarow:
>> formatFlag(row.cflags, row.ismsg))],
>>
>> ui='jquery-ui')
>>
>>
>> The 'links' attribute is working with the left attribute commented out.
>>
>> When removing the comment on the 'left' attribute, I do receive at runtime
>>
>> ERROR - Exception occurred in SQLFORM.grid : 'Row' object has no
>> attribute 'cflags'
>>
>>
>> I am new to web2py, maybe I missed something obvious with computed fields
>> and grid.
>>
>>
>> Thanks for your help
>>
>>
>> Seb
>>
>>
--
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/groups/opt_out.