I am dynamically creating the fields in a table from entries in another 
table. I am using SQLFORM.grid to view/edit the table. 

For the grid, the following field list works fine:
   fields=[db.monthly_projections.employee, db.monthly_projections.id, db.
monthly_projections.costcode,
           db.monthly_projections.Dec_2013, db.monthly_projections.Jan_2014,db
.monthly_projections.Feb_2014]

But, the problem is I don't know the complete field list ahead of time. So, 
I am using this instead:    
   fields=[db.monthly_projections.employee, db.monthly_projections.id, db.
monthly_projections.costcode] 
   for row in  db(db.months).select():
   fields.append('db.monthly_projections.'+ row.effort_month.strftime(
'%b_%Y'))

This is giving an error 
<type 'exceptions.AttributeError'> 'str' object has no attribute 'tablename'

On debugging, I see that the fields is created as three gluon.dal.Fields 
and three strings

 fields
[<gluon.dal.Field object at 0x0000000005414470>, 
<gluon.dal.Field object at 0x00000000046D7A58>, 
<gluon.dal.Field object at 0x0000000009F15D30>, 
'db.monthly_projections.Dec_2013', 
'db.monthly_projections.Jan_2014', 
'db.monthly_projections.Feb_2014']

So, I changed the definition of fields to:
   fields=[db.monthly_projections.employee, db.monthly_projections.id, db.
monthly_projections.costcode] 
   for row in  db(db.months).select():
   fields.append(Field('db.monthly_projections.'+ row.effort_month.strftime(
'%b_%Y')))

and this gives an error:
<type 'exceptions.SyntaxError'> invalid table or field name: 
db.monthly_projections.Dec_2013 
So, in short, how do I build the field list from string for SQLFORM.grid?

Thanks for your help!
PT

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to