Occasionally I have written a web2py app that makes use of a model/db from
another app. Basically, all that I do is define additional database
connections in models/db.py to the old app, and redeclare all the table
definitions.
I attempt to prevent accidental structure changes to the external tables by
adding migrate=false to the connection.
This works for me, but there may be some serious problems with this method
that I haven't considered.
In the following example, db2 and db3 are the connections to model/db from
another app.
I've included a few of the define_table statement to try to give you an
idea of what I did.
The controller example shows how the external databases are accessed.
I hope this answers your question. - Tom
--- snippets from models/db.py
db = DAL('mysql://******:******@*********/master')
db2 = DAL('oracle://******/*******@****', migrate=False) #
external
db3 = DAL('mysql://*****:*****@*********/semdb',migrate=False) #
external
db2.define_table('accessareaassignment',
Field('assignmentnumber','integer',writable=False),
Field('referencename','string',writable=False),
Field('setnumber','integer',writable=False),
Field('accessarea','integer',writable=False),
primarykey=['assignmentnumber'],
migrate=False
)
db3.define_table('scadaemail',
Field('type','string',default='Disabled'),
Field('email','string'),
Field('comment','string'),
)
--- code snippets from controllers/default.py
...
info = db3.scadapointlist(id)
form = SQLFORM(db3.scadapointlist,info,showid=False)
if (info.pointtype == 1):
pointname_info = db2(db2.statuspoint.pointnumber ==
info.pointnumber).select()
if (info.pointtype == 2):
pointname_info = db2(db2.analogpoint.pointnumber ==
info.pointnumber).select()
# if ((type == "None") or (point == "None")):
form.vars.pointname = pointname_info[0].pointname
...
grid = SQLFORM.grid(db3.scadaemail,
details=False,searchable=False,csv=False,showbuttontext=True,
fields=[db3.scadaemail.type,db3.scadaemail.email,db3.scadaemail.comment],
maxtextlengths=maxtextlengths,
)
On Thursday, June 27, 2013 1:03:09 PM UTC-6, Tom Russell wrote:
>
> I have 2 apps and one I want to use the model/db from it in the other in a
> SQLFORM.grid. I have read through and googled and cannot find a way to do
> this.
>
> Is this possible and how?
>
> Thanks,
>
> Tom
>
--
---
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.