I am thinking i could use a session to capture the initial user's service search which i would carry forward now in a session and make it a part of my database query, something like below:
CONTROLLER: def ajaxlivesearch(): keywords = request.vars.keywords print "Keywords: " + str(keywords) if keywords: query = reduce(lambda a,b:a&b,[db.services.service_name.contains(k) for k in keywords.split()]) services = db(query).select() *#CREATE MY SESSION HERE* * session.services=services* items = [] for c in services: items.append(DIV(A(c.service_name, _style="font-weight: bold;", _href=URL('companies', args=c.id), _id="res%s"%c.service_name, _onclick= "updatelivesearch(jQuery('#res%s').html())" % c.service_name))) var=DIV(*items) return DIV(*var) def Results(): def Results(): results=db.locations(request.args(0)) *#CALL MY SESSION HERE* rslts=db(db.business.place==results.id) *.select(db.business.services==session.services)* services=len(rslts) form=SQLFORM.factory(Field('query', requires=IS_NOT_EMPTY(), label=SPAN( '', _style="font-weight: bold;"), widget = lambda field, value: SQLFORM. widgets.string.widget(field, value, _class='my-string', _id='searching', _placeholder='LOCATION'))) #hiding the submit button searchBtn=form.element('input',_type='submit') searchBtn['_style'] = 'display:none;' if form.accepts(request): tokens=form.vars.query.split() query=reduce(lambda a,b:a&b, [db.locations.name.contains(k) for k in tokens]) location=db(query).select(orderby=db.locations.name) else: location=[] return locals() I tried it but its not helping but i know using a session can help me in this, anyone out there please help, Massimo, Anthony...anyone. Mostwanted On Sunday, March 17, 2019 at 5:41:12 PM UTC+2, mostwanted wrote: > > I have a table of companies that offer variable services, what i want is > to enable my users to search for companies that offer a desired service > *(which > i have been able to achieve)* and then from that very list of companies > displayed in that page be able to filter through them and search for > companies in a desired location offering that very same service *(this is > where i am facing a problem)* how do i achieve this because?? In terms of > searching I can only search for companies in a desired location but can not > combine my search to only display those of the searched service! > > *MODEL*: > db.define_table('locations', > Field('name'), > format='%(name)s') > def name_of(location): return '%(name)s' % location > > db.define_table('business', > Field('logo', 'upload'), > Field('company_name', requires=IS_NOT_EMPTY()), > Field('services', 'reference services'), > Field('product', 'reference product'), > Field('tel', requires=IS_NOT_EMPTY()), > Field('email', requires=IS_NOT_EMPTY()), > Field('fax', requires=IS_NOT_EMPTY()), > Field('cell', requires=IS_NOT_EMPTY()), > Field('facebook', requires=IS_NOT_EMPTY()), > Field('twitter', requires=IS_NOT_EMPTY()), > Field('website', requires=IS_NOT_EMPTY()), > Field('postal_address', requires=IS_NOT_EMPTY()), > Field('place', 'reference locations'), > Field('located_at', requires=IS_NOT_EMPTY())) > > *CONTROLLER*: > def companies(): > results=db.services(request.args(0)) > rslts=db(db.business.services==results.id).select(db.business.ALL, > orderby=db.business.company_name) > services=len(rslts) > form=SQLFORM.factory(Field('query', requires=IS_NOT_EMPTY(), label= > SPAN('', _style="font-weight: bold;"), widget = lambda field, value: > SQLFORM.widgets.string.widget(field, value, _class='my-string', _id= > 'searching', _placeholder='LOCATION'))) > searchBtn=form.element('input',_type='submit') > searchBtn['_style'] = 'display:none;' > if form.accepts(request): > tokens=form.vars.query.split() > query=reduce(lambda a,b:a&b, [db.locations.name.contains(k) for k > in tokens]) > location=db(query).select(orderby=db.locations.name) > else: > location=[] > return locals() > > def Results(): > results=db.locations(request.args(0)) > results2=db.services(request.args(0)) > #THIS IS WHERE I AM ATTEMPTING TO SELECT SERVICE PROVIDERS OF THE DESIRED > SERVICE IN A DESIRED LOCATION BUT THE ALGORITHM IS WRONG WHERE IT IS MARKED > IN RED,IT GIVES* (**<type 'exceptions.AttributeError'> 'Query' object has > no attribute 'type'**)* WHICH IS NO SURPRISE HONESTLY BECAUSE *results2 > *CARRIES > NOTHING, I WAS JUST DESPERATE!!! > HOW CAN I SELECT BOTH THE SERVICE AND LOCATION TO BE DISPLAYED IN THE > OTHER PAGE??? > rslts=db(db.business.place==results.id).select(db.business.services== > results2.id) > services=len(rslts) > return locals() > > *VIEW* > {{extend 'layout.html'}} > > {{for company in rslts:}} > {{=company.company_name}}<br /> > {{pass}} > > I hope my question is clear. > > Please help me, anyone???* (sad emojis)* > > 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.