Thank you!
On Monday, December 9, 2013 7:12:32 AM UTC-6, Massimo Di Pierro wrote:
>
> assuming the fields exist:
>
> 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'
> )])
>
> or
>
> fields=[db.monthly_projections.employee, db.monthly_projections.id, db.
> monthly_projections.costcode] + \
> [db.monthly_projections[row.effort_month.strftime('%b_%Y')] for row in
> db(db.months).select()]
>
>
> On Sunday, 8 December 2013 23:40:10 UTC-6, P T wrote:
>>
>> 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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.