Good day to all stackoverflow web2py Guru's here....
I found this link and its 2 years old now. I have a problem and I don't know how to code it.
I have 2 Entities(Tables) and it's a M:M relationship
First table: The Instructors (Advisers) Second table: The Lists of Students
now Advisers handled many students and students have many advisers right?
so I create a third table and I named it to Student_Adviser
School Year
db.define_table('school_year',
Field('sy',),
Field('current_year', 'boolean'))
List of Students
db.define_table('student_list',
Field('lastname'),
Field('firstname'))
these are the fields in Student_Adviser
db.define_table('stud_adviser',
Field('sy_id', 'reference school_year', label='School Year'),
Field('adv_id', 'reference auth_user', label='Adviser'),
Field('stud_id', 'reference student_list', label='Student', unique=True)
)
in the controller
def getStudent():
form = SQLFORM.grid(db.Student_List, csv=False, create=False, selectable=(need code here))
return locals()
I ask this kind of question because it help the Advisers to get the list of students by activating multiple check boxes so after he/she choose the students he/she will click the submit button and viola all the checked data will automatically add to the Student_Adviser table. Is my idea is possible in web2py?
ADDITIONAL 1:
Please also add a code that will automatic insert also the auth_user.id who is logged-in.
Let's say when Instructor 1 auth_user.id is 1
Instructor 1 is logged-in so all the transaction he/she will do the default value of adv_id in Student_Adviser table will always be 1 and so on.
ADDITIONAL 2:
I'm getting an error when I tried to manual add the data in the Student_Adviser table using the db interface.
btw how will I post a Traceback error? the Code Sample won't work in Traceback. I can't post the error because it will destroy the format... but this is the last line of error code (please based the table in Student_Adviser).
IntegrityError: foreign key constraint failed