Hey AGRogers, thanks for that suggestion, I added the highlited lines to my
model code & it gave results, thank you very much:
db.define_table('lecturer',
Field('surname'),
Field('name'),
Field('title'),
Field('posted_by', 'reference auth_user', default=auth.
user_id, readable=False, writable=False),
* common_filter = lambda query: db.lecturer.posted_by ==
auth.user_id,*
format="%(surname)s %(name)s %(title)s")
def lecturer(details): return '%(surname)s %(name)s' % details
db.define_table('subject',
Field('subject_name'),
Field('posted_by', 'reference auth_user', default=auth.
user_id, readable=False, writable=False),
* common_filter = lambda query: db.subject.posted_by ==
auth.user_id,*
format="%(subject_name)s"
)
db.define_table('departments',
Field('department_name'),
Field('posted_by', 'reference auth_user', default=auth.
user_id, readable=False, writable=False),
* common_filter = lambda query: db.departments.posted_by ==
auth.user_id,*
format="%(department_name)s")
db.define_table('lecture',
*Field('subject_name', 'reference subject'),
Field('department', 'reference departments'),* #HERE
Field('theLevels', label=SPAN('Levels'), requires=IS_IN_SET
(['1.1', '1.2', '2.1', '2.2', '3.1', '3.2', '4.1', '4.2'], zero='---Select
A Level---')), #HERE
* Field('lecturer', 'reference lecturer'),*
Field('class_session', requires=IS_IN_SET(['single session',
'double
session', 'evening single session', 'evening double session'], zero='----Select
A Session Period----')),
Field('the_time2', readable=False, writable=False),
Field('class_room', requires=IS_IN_SET(['500', '501', '502',
'503', '504', '505', '506'], zero='---Select A Class Room---')),
Field('controller', readable=False, writable=False),
Field('posted_by', 'reference auth_user', default=auth.
user_id, readable=False, writable=False))
Regards;
Mostwanted
On Sunday, July 19, 2020 at 1:13:06 PM UTC+2, AGRogers wrote:
>
> I would try using a common_filter on the drop down list table. Could that
> work?
>
> On Sun, 19 Jul 2020, 6:10 pm mostwanted, <[email protected] <javascript:>>
> wrote:
>
>> In my application I have 4 tables, 3 of them referenced in the fourth
>> table but every user should be able to view only what they have entered
>> into the database. Is there a way that in a dropdown list of a referenced
>> table in an SQLFORM users can only view & select from items they have
>> entered?
>>
>> *MODELS CODE:*
>> db.define_table('lecturer',
>> Field('surname'),
>> Field('name'),
>> Field('title'),
>> Field('posted_by', 'reference auth_user', default=auth.
>> user_id, readable=False, writable=False), #HERE
>> format="%(surname)s %(name)s %(title)s")
>> def lecturer(details): return '%(surname)s %(name)s' % details
>>
>> db.define_table('subject',
>> Field('subject_name'),
>> Field('posted_by', 'reference auth_user', default=auth.
>> user_id, readable=False, writable=False), #HERE
>> format="%(subject_name)s"
>> )
>> db.define_table('departments',
>> Field('department_name'),
>> Field('posted_by', 'reference auth_user', default=auth.
>> user_id, readable=False, writable=False), #HERE
>> format="%(department_name)s")
>>
>> db.define_table('lecture',
>>
>> *Field('subject_name', 'reference subject'),
>> Field('department', 'reference departments'),* #HERE
>> Field('theLevels', label=SPAN('Levels'), requires=
>> IS_IN_SET(['1.1', '1.2', '2.1', '2.2', '3.1', '3.2', '4.1', '4.2'],
>> zero='---Select
>> A Level---')), #HERE
>> * Field('lecturer', 'reference lecturer'),*
>> Field('class_session', requires=IS_IN_SET(['single
>> session', 'double session', 'evening single session', 'evening double
>> session'], zero='----Select A Session Period----')),
>> Field('the_time2', readable=False, writable=False),
>> Field('class_room', requires=IS_IN_SET(['500', '501',
>> '502', '503', '504', '505', '506'], zero='---Select A Class Room---')),
>> Field('controller', readable=False, writable=False),
>> Field('posted_by', 'reference auth_user', default=auth.
>> user_id, readable=False, writable=False))
>>
>>
>>
>> *CONTROLLER CODE:*
>> I tried the highlighted part but it didnt work, I felt it wouldnt work
>> but tried it anyway & it didnt work (shocker!)
>> Please help me figure this out.
>> def index():
>>
>>
>> *user=db.auth_user(auth.user_id) if not user or
>> not(user.id==auth.user_id): redirect(URL('index'))
>> form=SQLFORM(db.lecture.posted_by==user.id)*
>> if form.process(onvalidation=my_form_processing).accepted:
>> response.flash=T('Lecture Entered')
>> return locals()
>>
>>
>> Regards;
>>
>> Mostwanted
>>
>> --
>> 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] <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/web2py/e98d4e6a-69a2-4c1c-9028-3d98579a0f59o%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/web2py/e98d4e6a-69a2-4c1c-9028-3d98579a0f59o%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
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/a7a24094-6fea-465c-9a7d-eeb582c2acaco%40googlegroups.com.