Hi all,
I have the following situation:
1) I have a table that has a Virtual something attached to it that what it
does is it concatenates two other fields of that table.
db.define_table('tableaa', Field('afield', 'string', required=True ),
Field('bfield', 'string', required=True ),
)
db.tableaa.virtfield = Field.Virtual( lambda row: XML("<strong>" +
row.tableaa.afield + '</strong><br> ' + row.tableaa.bfield ))
When this something is a virtual field, as is the case then the two fields
it concatenates need to be in every query I select from that table or I get
an error regardless of whether the virtual field is in the list of selected
fileds or not. So I cannot just select afield without selecting bfield as
well.
When this something is a virtual method db.tableaa.virtfield =
Field.Method( lambda row: XML("<strong>" + row.tableaa.afield +
'</strong><br> ' + row.tableaa.bfield )) then the above situation does not
exist however
a) when i use it as sqltable = SQLTABLE( db(db.tableaa.id > 0).select(
db.tableaa.virtfield ) , columns = ['db.tableaa.virtfield']) I get a DB
error saying the field does not exist, which is correct since it exists in
the web2py layer than the db layer
b) when i use it as sqltable = SQLTABLE( db(db.tableaa.id > 0).select( ) ,
columns = ['db.tableaa.virtfield']) I get a <gluon.dal.VirtualCommand
object at 0x2abddb8f4910>
c) when i use it as sqltable = SQLTABLE( db(db.tableaa.id > 0).select(
db.tableaa.virtfield() ) , columns = ['db.tableaa.virtfield']) I get a
TypeError: 'FieldMethod' object is not callable
d) when i use it as sqltable = SQLTABLE( db(db.tableaa.id > 0).select( ) ,
columns = ['db.tableaa.virtfield()']) I get a AttributeError: 'Row' object
has no attribute 'virtfield()'
e) when I tried to use it as an extracolumn in the form of
extracolumns = [{'label':virtfiled label,
'class': '', #class name of the header
'width':'60%', #width in pixels or %
'content':lambda row, rc: row.tableaa.virtfield(),
'selected': False #agregate class selected to this
column
}]
then there is no reason to include anything from the original query in the
columns variable or the SQLTABLE sqltable = SQLTABLE( db(db.tableaa.id >
0).select( ) , columns = [], extracolumns = extracolumns ) and I could not
find a way to nullify that, I have tried sqltable = SQLTABLE(
db(db.tableaa.id > 0).select( ) , columns = [], extracolumns = extracolumns
) , sqltable = SQLTABLE( db(db.tableaa.id > 0).select( ) , columns = None,
extracolumns = extracolumns ) and sqltable = SQLTABLE( db(db.tableaa.id >
0).select( ) , columns = [ None ], extracolumns = extracolumns ) all
failing for different reasons.
Any ideas on how to overcome this ? To tell you the truth I would like to
go with the virtual method way if I have that option.
Thanks in advance guys.
Kind regards,
Zach
--
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.