Deepak
Deepak

Reputation: 1545

using appadmin for other models than db.py in web2py

in web2py we I created a new application called imageblog and in models on default I have 2 models :

db.py
menu.py
coffee.py   #this is new one created by me in models i made some tables inside this too

and if I use the url

http://127.0.0.1:8000/imageblog/appadmin/

I can see the appadmin of the db.py model but my question is I created another model called coffee.py how can I open coffee.py in appadmin? I tried:

http://127.0.0.1:8000/imageblog/coffee/appadmin

I get output as : "invalid function (coffee/appadmin)" but no luck. Is appadmin only available for db.py ???

==================================================================================

so as I researched a little more and everybody is telling me I should be able to access all the models from appadmin so i think its might be my code is doing something wrong so i am pasting the model in coffee.py:

db = DAL("sqlite://storage.sqlite")

db.define_table('cimage',
   Field('title', unique=True),
   Field('file', 'upload'),
   format = '%(title)s')

and in appadmin i get the following:

Available Databases and Tables

db.auth_user    New Record
db.auth_group   New Record
db.auth_membership  New Record
db.auth_permission  New Record
db.auth_event   New Record
db.auth_cas New Record

Upvotes: 0

Views: 519

Answers (1)

Anthony
Anthony

Reputation: 25536

In appadmin, you will be able to access database tables for any model defined in any model file.

Update (based on info posted to the web2py user group):

The problem is that you are defining db = DAL(...) in both coffee.py and db.py. Because db.py comes after coffee.py, the db object defined in coffee.py is simply replaced by the one defined in db.py, so none of the models in coffee.py will be available to any controller, including the appadmin controller.

You should define the db object only once, in the first model file that runs (model files run in alphanumeric order).

Upvotes: 1

Related Questions