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)



Reply via email to