# I have this code to create a table:
*db.define_table('event',*
* Field('event_type', length=8),*
* Field('created', 'datetime', default=request.now),*
* )*
# Now, I have numerous fields (20 in real life) that should build up this
table, which is why I would like to generate them from a list.
*influences = ['gravity','magnetism']*
# So, I want to dynamically add this fields gravity_x, gravity_y,
magnetism_x, magnetism_y, to the table
*for influence in influences:*
*setattr(db.event, influence+'_x', Field(influence+'_x') )* # should do
something like db.event.gravity_x = Field() -- a failed attempt to append
the gravity_x field
*setattr(db.event, influence+'_y', Field(influence+'_y') )* # should do
something like db.event.gravity_y = Field() -- a failed attempt to append
the gravity_y field
Is it possible to do what I want? Maybe another way would be to call a
**dict on db.define_table?
--
---
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.