Good day to all members here in stackoverflow and to all expert level in web2py!
This is about the School Year, Student List (Masterlist) and Organization Fines using the existing code that @Anthony Anthony gave me.
these are my database:
lets start on School Year:
db.define_table('school_year',
Field('sy',),
Field('current_year', 'boolean'),
format='%(sy)s')
next for the student list
db.define_table('student_list',
Field('lastname'),
Field('firstname'),
Field('middlename'),
Field('address'),
format='%s, %s' % ('%(lastname)s', '%(firstname)s'))
and last for the Organization Fines table
db.define_table('org_fines',
Field('sy_id','reference school_year'),
Field('stud_id', 'reference student_list'),
Field('total_fines', 'double'),
Field('date', 'datetime'),
Field('paid', 'boolean'))
this is the original code by Anthony
db.stud_adviser.sy_id.default = db.school_year(current_year=True).id
db.stud_adviser.adv_id.default = auth.user_id
def add_students(ids):
for id in ids:
db.stud_adviser.insert(stud_id=id)
form = SQLFORM.grid(db.student_list, create=False, selectable=add_students, csv=False, paginate=13)
and this the code I modified and still I can't make it work.
db.org_fines.sy_id.default = db.school_year(current_year=True).id
def members_fines(ids):
for id in ids:
db.org_fines.insert(stud_id=id)
form = SQLFORM.grid(db.student_list, create=False, selectable=members_fines, csv=False)
Anthony said on the comment and still some of his comment I don't understand (because Finals is coming):
The selectable argument is a callback function, which receives the list of record IDs selected in the grid. The add_students function supplied as that argument loops through the IDs and inserts a new record in the stud_adviser table for each one. Because the school year and adviser IDs should be the same for each record, they are set by setting the default attributes of their respective fields (for the school year, I assume you want the ID of the current school year) -- by excluding those fields from the .insert() call, the default values will be inserted automatically.
based on this comment:
Because the school year and adviser IDs should be the same for each record
since I don't have adviser ID in the org_fines table is it possible to use the code that Anthony gave it to me?
Direct question for Anthony
I still I don't get it: what are the difference on this codes: auth_user_id, auth_user.id and auth.user_id? when and where will I use these code? please enlighten me thanks in advance