Thank you Alan.

But the problem is that the data entered from, say index() is not available 
at db.py. Am I right?
If a user enters entries to table "table_names", will db.py see them? Are 
the data persistent?

Also my understanding from reading the online book is that the model files 
are run once when starting the application. Could you tell me how I can 
make the for-loop run after each user enters a entry in the table?

Thank you.

On Friday, April 27, 2012 11:29:30 AM UTC+9, Alan Etkin wrote:
>
> 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.
>>
>

Reply via email to