>
> db = DAL('sqlite://se2.sqlite',check_reserved=['postgres',
> 'postgres_nonreserved'],pool_size=10,lazy_tables=False, migrate=True,
> fake_migrate=False)
> now I got right results:
> >>> db.ta._fields
>
>
> ['id', 'f1', 'newfield']
>
> *BUT it does not work in the web app*. session.flash = db.ta._fields -
> giving me right result (['id', 'f1', 'newfield']) BUT in the table (app
> /appadmin) and SQLFORM.grid I don't have any change. Any idea why it is
> not working in the app?
>
A DAL model exists only during a single request. If you create a model in
one request, web2py won't know anything about that model in a subsequent
request, unless that model is redefined on each request (of course the
database table itself will persist, but on each request, you still need to
generate a model of that table so web2py knows how to interact with the
database).
Do you really need to allow database tables to be changed arbitrarily on a
continual basis, or is there just some initial setup process to define the
table structure? If the latter, you might consider an alternative for
specifying a custom but fixed table definition on a one-time basis.
If you really need dynamic definitions, a better approach would probably be
to store the metadata needed for the table definitions in a Python data
structure (e.g., a dictionary of dictionaries). Then, to define the table
in a model, parse the data structure to generate the arguments to
db.define_table().
Another option would be to programmatically generate an actual model file
(you could even use the web2py template language to do so). Whenever the
table definition needs to change, re-generate the relevant model file.
Anthony
--
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.