[web2py] Re: Model with many to many defined across multiple database instances

2010-09-01 Thread ron_m

 Commenting out the following lines shows servers as a drop down list
 on the insert site_servers form, leaving the line active causes the
 servers line to be a text input field.

 # Test for uniqueness across site_id and server_id
 db.site_servers.server_id.requires = IS_NOT_IN_DB(db

 (db.site_servers.site_id==request.vars.site_id),db.site_servers.server_id)

Sorry I was looking in the forum and did not find the answer, The
proper explanation is in the 3rd edition of the book Chapter 7 Forms
and Validators at the end of the IS_IN_DB() description. Use the 4th
parameter to IS_IN_DB()  _all = followed by the IS_NOT_IN_DB() code
above.

db.site_servers.server_id.requires = IS_IN_DB(db, 'servers.id', '%
(hostname)s',
_all=
IS_NOT_IN_DB(db(db.site_servers.site_id==request.vars.site_id),'db.site_servers.server_id')
 )
)

Added in case someone searches, finds this, at least they will see a
solution.


[web2py] Re: Model with many to many defined across multiple database instances

2010-08-23 Thread ron_m
To simplify I just used standard id fields, copied the scaffold
(welcome) application with create new application in admin and then

in db.py
changed the db line to match MySQL and created the database
else: # else use a normal
relational database
#   db = DAL('sqlite://storage.sqlite')   # if not, use SQLite or
other DB
db = DAL('mysql://xxx:y...@localhost/testing') # testing

then added the following to the bottom of the model file db.py


# Global table of known sites
db.define_table('sites',
Field('name', 'string', length=16, required=True, notnull=True,
unique=True, label='Site name'),
Field('long_name', 'string', length=64, unique=True, label='Site
full name'),
format='%(name)s'
)

# Global table of known servers
db.define_table('servers',
Field('hostname', 'string', length=64, required=True,
notnull=True, unique=True, label='Hostname:'),
format='%(hostname)s'
)

# Global table showing which servers perform known functions for which
sites.
# The default is a server provides all services.
db.define_table('site_servers',
Field('site_id', db.sites),
Field('server_id', db.servers),
Field('web_server', 'boolean', default=True),
Field('archiver', 'boolean', default=True)
)
db.site_servers.site_id.requires = IS_IN_DB(db, 'sites.id', '%
(name)s')
db.site_servers.server_id.requires = IS_IN_DB(db, 'servers.id', '%
(hostname)s')
sites_and_servers = db((db.sites.id==db.site_servers.site_id) 
(db.servers.id==db.site_servers.server_id))

Commenting out the following lines shows servers as a drop down list
on the insert site_servers form, leaving the line active causes the
servers line to be a text input field.

# Test for uniqueness across site_id and server_id
db.site_servers.server_id.requires = IS_NOT_IN_DB(db
 
(db.site_servers.site_id==request.vars.site_id),db.site_servers.server_id)