On Tuesday, May 10, 2011 6:58:05 PM UTC-4, james c. wrote:
>
> Prior to the select I defined and created a user named table by using
> the variable company_accounts_db. User_id 8 enters a company name
> within a form. The form input is used to define the variable db name
> by: company_accounts_db = company_name + '_accounts_' +
> str(auth.user_id)
> In this case, user_8 inputs for company name, BIGkittyBIG.(sorry for
> the goofy name but its easy to spot in the directory) Then the table
> is created with:
>
> db.define_table( company_accounts_db,
> Field('name'),
> Field('owner'),
> Field('plan'),
> Field('actual'),
> Field('status'))
Is this table defined within a controller function? Keep in mind that the db
object and its tables are created upon each request (not the database
itself, just the web2py DAL objects that represent the database and its
tables) -- they do not persist from one request to the next. So, if you
define table 'BIGkittyBIG_accounts_8' in func1() on one request, you will
not be able to reference it in func2() on a subsequent request. That's
probably why you're getting the KeyError -- when you try to refer to this
table in the second function, it hasn't actually been defined as one of the
tables in the db object. Usually tables are defined in model files, so they
are available to all controller functions on every request. You may somehow
need to repeat the table definition in the second function (or in a model
file). To keep things DRY, you can define a template table in a model file
and use table inheritance to define the specific tables where needed (see
http://web2py.com/book/default/chapter/06#Table-Inheritance). For example,
in a model file:
db.define_table('template',
Field('name'),
Field('owner'),
Field('plan'),
Field('actual'),
Field('status'))
And then in a controller function:
db.define_table(company_accounts_db, db.template)
> Access to the ...accounts_8.table is not available through the admin
> interface.
I believe appadmin only sees table definitions that are in the model files,
so if your table definition is in a controller (other than the appadmin
controller itself), then appadmin will not see the table definition and will
therefore not provide any administration functionality for that table.
Anthony