The easiest way is to put a common filter in client_order table, do something like this in your models
db.client_order._common_filter = lambda q:(db.client_order.company.belongs(db(db.business.authority==auth.user_id)._select(db.business.id))) This will AND this query to any other query you make on the table. A quarta-feira, 29 de março de 2023 à(s) 14:00:52 UTC+1, mostwanted escreveu: > This is supposed to be simple but i'm failing to make it work! If it were > about displaying the > > How can I get business owners of businesses listed in the business table > also referenced in clients_order table to view only requested orders of > their businesses in the client_order table? I hope I’m making sense! > > > *MODELS* > > db.define_table('business', > Field('logo', 'upload', label=SPAN('Your company logo')), > Field('banner', 'upload', writable=False, readable=False), > Field('company_name', ), > Field('product', 'reference product',), > Field('tel'), > > Field('authority', 'reference auth_user', > default=auth.user_id, readable=False, writable=False) > > ) > > db.define_table('client_order', > Field('company', 'reference business'), > Field('buyer_name', required=True), > Field('buyer_contact', required=True), > Field('delivery_location', required=True), > Field('quoted_item','list:string', required=True), > Field('quantities','list:string', required=True), > Field('status', requires=IS_IN_SET(['new', 'sent']), > default='new', writable=False, readable=False), > Field('the_timestamp', 'datetime', default=request.now, > writable=False), > format='%(buyer_name)s') > > > *CONTROLLERS* > > @auth.requires_login() > def wall(): > # get the business ID for the logged-in user > business_id = db.business(authority=auth.user_id) > > # check if the user has admin rights for the business > if not auth.has_membership(role='admin', business=business_id): > # if not, redirect them to a page indicating they don't have access > session.flash = 'You do not have permission to access this page' > redirect(URL('default', 'index')) > # get the client orders for the logged-in user's business > details = db(db.client_order.company == business_id).select() > > return dict(details=details) > > > @auth.requires_membership(role='admin') > def show_details(): > db(db.client_order.id == request.args(0, > cast=int)).update(status='sent') > details = db.client_order(request.args(0, cast=int)) > return dict(details=details) > -- 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/28b3b244-fa73-4713-9096-06373c931ea7n%40googlegroups.com.