why not just:
# start to form query:
q = db.counters.c_date >= datum_od
if ...: # continue to form the query depending on conditions  
   q &=...belongs(...)

# the same with `left`
left = ...
if ...:
   left.append(...)

# and fields
if ...:
   fields = [...]
else:
   fields = [...]

# at the end
rows = db(q).select(*fields, left = left)





On Thursday, May 30, 2019 at 4:41:52 PM UTC+3, Yebach wrote:
>
> Hello
>
> I have a query where the possibility for belongs can be a set of values or 
> it can be empty. 
> In case the set is empty I want the query to act as 1=1 and not 1=0, so 
> all values would be selected.
>
> Any suggestions??
>
> Thank you
>
> This is my query
>
> selected = list(selected_values_str.split(","))
>             selected_int  = tuple([int(i) for i in selected])
>             rows = db((db.counters.c_date >= datum_od) &
>                 (db.counters.c_user_inserted.belongs(selected_int)) &
>                 (db.counters.c_date <= datum_do) &
>                 (db.machines.m_status != 
> 100)).select(#db.counters.c_machine_id,
>                                                       db.counters.c_total,
>                                                       db.counters.c_black,
>                                                       db.counters.c_color,
>                                                       db.counters.c_level1,
>                                                       db.counters.c_level2,
>                                                       db.counters.c_level3,
>                                                       
> db.counters.c_a3_color,
>                                                       db.counters.c_date,
>                                                       
> db.counters.c_datetime,
>                                                       
> db.counters.c_datetime_dataread,
>                                                       db.counters.c_scans,
>                                                       db.counters.c_note,
>                                                        db.machines.m_code,
>                                                       
>  db.auth_user.first_name,
>                                                       
>  db.auth_user.last_name,
>                                                        db.auth_user.email,
>                                                       
>  left=[db.machines.on(db.counters.c_machine_id == db.machines.id),
>                                                             
>  db.auth_user.on(db.counters.c_user_inserted== db.auth_user.id)]
>                                                       ).as_list()
>

-- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/45236860-31a6-4648-8a6c-65e159d1d972%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to