This:
<code>
class ExtraField:
def new_column(self):
if self.task.id==1:
return A('some_action_link',
_href=URL(f='default',
args=[self.task.id]))
else:
return A('great thing', _href='http://www.web2py.com')
def test():
rows=db(db.task).select()
rows.colnames.append('task.new_column')
rows.setvirtualfields(task=ExtraField())
table=SQLTABLE(rows)
return dict(table=table)
</code>
Is not working raising this error:
Traceback (most recent call last):
File "/Users/brunomac/web2py/gluon/restricted.py", line 188, in restricted
exec ccode in environment
File "/Users/brunomac/web2py/applications/satlite/controllers/teste.py"
<http://127.0.0.1:8000/admin/default/edit/satlite/controllers/teste.py>,
line 71, in <module>
File "/Users/brunomac/web2py/gluon/globals.py", line 96, in <lambda>
self._caller = lambda f: f()
File "/Users/brunomac/web2py/applications/satlite/controllers/teste.py"
<http://127.0.0.1:8000/admin/default/edit/satlite/controllers/teste.py>,
line 20, in test
table=SQLTABLE(rows)
File "/Users/brunomac/web2py/gluon/sqlhtml.py", line 1241, in __init__
File "/Users/brunomac/web2py/gluon/sql.py", line 3787, in __str__
self.export_to_csv_file(s)
File "/Users/brunomac/web2py/gluon/sql.py", line 3771, in export_to_csv_file
field = self.db[t][f]
File "/Users/brunomac/web2py/gluon/sql.py", line 1668, in __getitem__
return dict.__getitem__(self, str(key))
KeyError: 'new_column'
2010/12/9 Ivan Matveev <[email protected]>
> You can put anything in SQLTABLE by modifying Rows object with
> rows.setvirtualfields.
> See this post
> http://groups.google.com/group/web2py/browse_thread/thread/826a37f56c26d689
>
--
Bruno Rocha
http://about.me/rochacbruno/bio