I think that you could use a common table for storing user input and then
have a loop in a model file for creating each new table from the stored db
definition records
Example:
db.define_table("table_names", Field("name"))
for row in db(db.table_names).select():
db.define_table(row.name, Field("my_field"))
It could be possible also to use one-to-many relations for adding table
fields to each new table with form input.
On Thursday, April 26, 2012 11:06:47 PM UTC-3, Madu wrote:
>
>
> Hello,
>
> I'm new to web2py and to web frameworks in general and I am trying to
> learn the MVC model and web2py by coding.
> What I'm trying to do is to have a user create tables and entries in a DB
> that I have defined in dv.py:
>
>> *TestDB = DAL("sqlite://storage.sqlite")*
>
>
> Now in index() I'm trying to do as follows:
>
>> *
>> ** def index():
>> *
>
> * form = FORM(INPUT(_name='name', requires=IS_NOT_EMPTY()),*
>
> * INPUT(_type='submit'))*
>
> * if form.process().accepted:*
>
> * TestDB().define_table(form.vars.name, Field('testField', unique=True))*
>
> * return dict(form=form)*
>
> * **return dict(form=form)*
>
>
> This works (i.e. no errors) but I cannot see the created entry in
> appadmin. From an answer I got in StackOverflow it's because what I do in
> index() is not persistent.
> I'd like to know what is the proper way of achieving this.
>
>
> Thank you.
>
>
> Regards,
> Madu.
>