On Friday, May 12, 2017 at 11:59:43 AM UTC-7, Toe Khaing Oo wrote: > > It works on data parsing .. But I have some difficulties with this. There > are many students to update record into table. How can I insert one student > by one. > > Thanks for your help >
It sounds like you want a table that can be updated. You might want to take a look at SQLFORM.grid <URL:http://web2py.com/books/default/chapter/29/07/forms-and-validators#SQLFORM-grid> I would use this perhaps to record attendance in a class if the list of students was not changing much. (There are also some javascript "spreadsheet" tools available (datatables.net seems to be popular in this group; Tom Campbell had an example that did *display*, back at the end of '15, but that doesn't show *updating* the db). <URL: https://groups.google.com/d/topic/web2py/z0TVv2pbWGw/discussion>) If you want a form where you select an individual student, and the system figures out which class to update, and you do this one student at a time, then SQLFORM may be the place to start (perhaps using the "linkto" argument). If you already have the data in a file (a CSV file,perhaps), then look at the import techniques at <URL:http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Exporting-and-importing-data> > On Saturday, May 6, 2017 at 6:03:07 PM UTC-7, pbreit wrote: >> >> I think you're on the right track. It's a personal thing but I like >> defining my tables in the singular (ie, class, student, attendence). >> >> As Donald indicated, your current model is best suited for each student >> only being in one class (which is fine for elementary school). It would >> work for students taking multiple classes but each student would be >> represented multiple times in DB. >> >> I don't think "default=db.classes.id" is going to work. >> >> You could have some controllers like: >> >> def class_list(): >> classes = db(db.classes.id>0).select() >> return dict(classes=classes) >> >> def class(): >> class = db.classes(request.args(0, cast=int)) or >> redirect(URL('class_list')) >> students = db(db.students.class_id==class.id).select() >> return dict(class=class, students=students) >> >> def attendance(): >> db.attendance.update(class_id=request.vars.class_id, >> student_id=request.vars.student_id, Attend=attendance) >> response.flash = 'Attendance recorded' >> redirect URL('class_list', args=[class_id]) >> >> Once you get this working, you could investigate an Ajax approach. >> >> > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.