This is  very wrong:

 q1 = eval('db. userLanguage.'+ language )== True

what is it supposed to be?


 q1 = db.userLanguage[language] == True

I am not sure. Once q1 is correct, this works:

 results = db(q1 & q2).select()

On Wednesday, 25 June 2014 17:04:28 UTC-5, Riccardo C wrote:
>
> Dear all,
>
> I am trying to formulate a query to get ALL the people that know a 
> language AND leave in a specific city.
> As I am not an expert I thought that was a good idea to have two tables as 
> following:
> auth.settings.extra_fields['auth_user']= [ 
> Field('city',requires=IS_IN_SET(('UK - London','IT - Milano','USA - New 
> York')) )]
>
>
> db.define_table('userLanguage',
>     Field('idUser','reference auth_user', unique=True),
>     Field('French','boolean',default = False),
>     Field('Italian','boolean',default = False),
>     Field('Chinese','boolean',default = False),
>     Field('Indian','boolean',default = False))
>
> in term of controller search function I decided to get the information 
> from the URL (that in my idea will be generate from a javascript function 
> depending of what the user select on the page):
> def search():
>     
>     lstLanguages = ['French',   'Italian',    'Chinese',    'Indian']
>
>     lstCity = ['UK - London','IT - Milano','USA - New York']
>     
>     language = lstLanguages[int(request.vars.n)]
>     userCity = lstCity[int(request.vars.c)]
>     
>     q1 = eval('db. userLanguage.'+ language )== True
>     q2 = db.auth_user.city  == userCity
>     
>     """ QUERY: give me the list of users that know that language and live 
> in that city"""
>
>     
>     return dict(form = chefResults)
>
> As written above I tried different way to do that (without succed):
>
> results = db(q1 & q2).select() """ gives me, as expected the sum of the 
> two query results"""
> -------------------------------
> results2 = db(q1).select() '''this return those who speak the selected 
> language'''
> searchresults = [row for row in results2 if results2.idUser_city == 
> userCity] '''this make web2py to crash! I have to kill the process...why?'''
>
> I hope to not have bother you too much, I would like to learn and 
> understand... in particular:
> 1) which is the best way of doing this kind of query?
> 2) is there a better way of structuring the data (db tables) 
> 3).... why it crashes?!
> 4) what would be the best way to pass the search criteria to the function? 
>
> Thanks for any answer and I hope it might be useful for other people as 
> well.
>
> Regards, 
>
> Riccardo
>
>
>
>

-- 
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.

Reply via email to