I do not fully understand. You want a create incident form but that does not have a school field. I guess what you want is display only students for the same school as the logged in staff. In this case you can do
school_id=db.staff[userid()].school if userdi() else None db.incident.student.requires=IS_IN_DB(db (db.student.school==school_id),'student.id','student.lastfirst') Massimo On Jun 9, 10:59 am, Gutch <[email protected]> wrote: > Hello, > > Sorry if this question is a repeat, but I'm new here and couldn't find > anything on point in the archive. > > I'm trying to create a form for data insertion, which will include a > dropbox representing a foreign key. Trouble is, the foreign table has > another key representing the row's 'school', which corresponds to the > 'school' of the logged-in user. I only want the dropbox to represent > rows whose school entry matches that of the user. > > Is there any way to accomplish this with a SQLFORM? I could use a > FORM, a SQLFORM in HTML, or I could modify the SQLFORM class, but I'd > like to keep my code as simple and reusable as possible. > > Here's the relevant code: > > From db.py: > > db.define_table('school',SQLField('name','string'), > SQLField('schoolnumber','integer') > ) > db.define_table('student',SQLField('school',db.school), > SQLField('home_room','string'), > SQLField('lastfirst','string',length=35), > SQLField('student_number','integer'), > SQLField > ('enroll_status','integer',default=0) > ) > db.define_table('incident',SQLField('student',db.student), > SQLField('starttime','datetime'), > SQLField('endtime','datetime'), > SQLField('rpttime','datetime'), > SQLField('activity','string'), > SQLField('location','string') > ) > db.define_table('staff',SQLField('school',db.school), > SQLField('emp_number','integer'), > SQLField('last_name','string'), > SQLField('first_name','string'), > SQLField('jobtitle','string') > ) > db.student.school.requires=IS_IN_DB(db,'school.id','school.name') > db.incident.student.requires=IS_IN_DB > (db,'student.id','student.lastfirst') > db.staff.school.requires=IS_IN_DB(db,'school.id','school.name') > > From the controller: > > def incident(): > uid = userid() > s = session.school > staffname=db(db.staff.id==uid).select > (db.staff.first_name,db.staff.last_name) > incidentform=SQLFORM(db.incident) #I want the student dropbox > populated only with values in > #db > (db.student.school==s).select(db.student.id,db.student.lastfirst) > return dict(staffname=staffname[0].first_name.capitalize > (),incidentform=incidentform) > > From the view: > > {{extend 'layout.html'}} > <h1>This is the incident.html template</h1> > <h2>Hello, {{=staffname}}!</h2> > {{=incidentform}} --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---

