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('tlamelo', 'reference tlamelo'),
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, 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 [email protected].
For more options, visit https://groups.google.com/d/optout.