[web2py] Re: variable query

2015-02-02 Thread José Eloy
Sorry for my delay in answer. Anthony: Your solution works well: db(db.articulos.id.belongs(list_of_ids)).select() Creating a list of ids and using belongs was the correct for me. Thanks guys for the help. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://gi

[web2py] Re: variable query

2015-01-28 Thread Anthony
> Antony: Your solution sounds well, but, How I can build the query > dinamically as you propose? Can you write an example? > I don't think you want to simply take the 11 consecutive integers preceding the max id, as there may be gaps due to deletions. Anyway, if you did have a list of ids, r

[web2py] Re: variable query

2015-01-28 Thread Leonel Câmara
Here's a possibility from operator import or_ query_list = [] for i in range(limite_bajo,maxID): cuenta+=1 if cuenta%2==0: # only the even records are saved query_list.append(db.articulos.id== i) even_query = reduce(or_, query_list) -- Resources: - http://web2py.com - http://web

[web2py] Re: variable query

2015-01-28 Thread Niphlod
uhm, not quite. Leonel has the "mathematically right" solution...or you didn't explain your requirements well. Given ids ranging from 1 to 31, i.e. 1,2,.,30,31 your requirement, i.e. "I need to get the last 11 records from my database, but only the even" needs to fetch 11,13,15,17,19,21,2

[web2py] Re: variable query

2015-01-28 Thread José Eloy
Thanks Leonel and Anthony for your answers. Leonel: Your solution works well if the id are consecutive (this fail if user delete a record). Antony: Your solution sounds well, but, How I can build the query dinamically as you propose? Can you write an example? Regards. -- Resources: - http

[web2py] Re: variable query

2015-01-27 Thread Anthony
If you are writing the SQL manually, you cannot have "db." in the table names, as that is Python code, not SQL. Anyway, this is probably not the best approach because IDs may not remain consecutive integers (e.g., if you delete a record). Instead, maybe it would be simpler to just select that l

[web2py] Re: variable query

2015-01-27 Thread Leonel Câmara
This one is simpler than it looks. Heres how you could get the even numbers from the last 11 rows in just one line: db((db.articulos.id % 2) == 0).select(orderby=~db.articulos.id, limitby=(0, 11)) -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web