I wanted to use SQLFORM. Whenever teacher logged in, he has to select from combobox only their responsible students. I could not find the way how to implement it while creating SQLFORM. My solution: I've added one hidden text into form and parse on the client side like this: form = SQLFORM( table_sessions, fields=field_list, hidden=dict(student_list=get_students())) if form.process().accepted: ...
And on client side I used jQuery to parse. Thanks for reply. ------------------------------- Murat KAŞIKÇIOĞLU Dave S <snidely....@gmail.com>, 11 Tem 2019 Per, 02:32 tarihinde şunu yazdı: > > > On Tuesday, July 9, 2019 at 11:23:07 PM UTC-7, Murat KAŞIKÇIOĞLU wrote: >> >> I want to select only authenticated teachers' students on the form. But I >> could not find how to filter. Can you help? >> > > I don't find it easy to picture what you want. > > My best guess is that when a teacher is logged in, you want to show a list > of students who are in a session where the session teacher field is the > logged-in teacher. Wouldn't that be just a query like > > rows = db(db.session_header.teacher == auth.user_id).select() > > You would put this in another controller function > > def showmystudents(): > rows = ... > return dict(vrows = rows) > > and in the matching view you would populate a table or use SQLTABLE(). > > Or you combine some of the steps (and provide for editing) by using > SQLFORM.grid() > <URL: > http://web2py.com/books/default/chapter/29/07/forms-and-validators#SQLFORM-grid > > > > > > > Best, >> Murat. >> >> > /dps > > >> ### >> db.define_table( >> 'session_header', >> Field('session_date', type="date", label='Session Date'), >> Field('teacher', 'reference auth_user', notnull=True, readonly=True, >> default=auth.user_id), >> Field('student', 'reference student', notnull=True), >> auth.signature) >> >> def create(): >> form = SQLFORM(session_header) >> if form.process().accepted: >> response.flash = "Record inserted successfully." >> elif form.errors: >> response.flash = "Please correct the form errors." >> response.view = 'sessions/create.html' >> return dict(form=form) >> >> >> -- > 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. > To view this discussion on the web visit > https://groups.google.com/d/msgid/web2py/391ac387-13b0-42bb-a5d6-abd0d4fa08ec%40googlegroups.com > <https://groups.google.com/d/msgid/web2py/391ac387-13b0-42bb-a5d6-abd0d4fa08ec%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/CAC5t_JxDWvx%3Dgo_A5Z%3DE3Ji05z82d4zcro8EtUtzoTX-x4FTmQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.