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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/391ac387-13b0-42bb-a5d6-abd0d4fa08ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.