I am trying to create a form to input data for a particular item. For 
example, I would like to store the item's location, area, and owner. 
 An example is I have an owner, an area (Items location), and the item. 
When I go to input a new "item", I need to select the "owner", then the 
dropbox below it needs to show me a list of all the "areas" the "owner" 
has. For example, If Bob (the owner), has 3 locations, his 3 locations 
would show up, but not pauls location (Another owner.) This allows me to 
sort data and areas by owner. It allows me to enter data by owner. It 
allows me to enter areas for owner. The owner would be akin to their 
address(es). When I go to the 'add_area' page, it shows a drop box of all 
of the owners, but when I go to the 'add_item' page, it only shows me the 
owner dropbox, and not the area options.



In Model:

db.define_table('owner',
    Field('name'),
    Field('notes')
    )
    
db.define_table('area',
    Field('owner', db.owner),
    Field('name'),
    Field('note', 'text'))

db.define_table('item',
    Field('owner', db.owner),
    Field('area_id', db.area),
    Field('date', 'date'),
    Field('note'),
    Field('picture', 'upload', default=''),
    Field('flag', 'boolean', default='False'))

In Controller:
def add_owner():
    form = SQLFORM(db.owner)
    if form.process().accepted:
        response.flash = 'New Owner Entered'
    return dict(form=form)

def add_area():
    form = SQLFORM.factory(
        Field('building_id', requires=IS_IN_DB(db, db.owner.name, 
'%(name)s')),
        Field('area', 'string'),
        Field('note', 'text'))

        
    if form.process().accepted:
        response.flash = 'New Area Added'
    return dict(form=form)
    
def add_item():
    form = SQLFORM.factory(
        Field('owner_id', requires=IS_IN_DB(db, db.building.name, 
'%(name)s')),
        Field('area_id', requires=IS_IN_DB(db, db.area.name, '%(name)s')),
        Field('date', 'date'),
        Field('picture', 'upload', default=''),
        Field('note', 'text'),
        Field('flag', 'boolean')
    )

Reply via email to