Select records NOT in a set

52 views
Skip to first unread message

backseat

unread,
Sep 15, 2019, 3:20:45 PM9/15/19
to web2py-users
I have a list of members that I want to schedule for certain duties. One table lists the people:

db.define_table(
    'members',
    Field('fullname', type='string', label='Name'),
    [...]
)

I select members from that table according to certain criteria, but I want to not select them if they are unavailable on a given date.

I have:

db.define_table(
   
'unavailable',
   
Field('the_date', type='date', label='Date'),
   
Field('who', type='reference members', label='Name')
)

It is possible, given a date and the other selection criteria, to get a list of available members for the date in question?

Massimo Di Pierro

unread,
Sep 16, 2019, 10:57:02 AM9/16/19
to web2py-users
s = datetime.date(2020,1,1)
subquery = db(db.unavailable.the_date==s)._select(db.unavailable.who) # notice _select
db(~db.members.id.belongs(subquery)).select(db.members.ALL)

backseat

unread,
Sep 16, 2019, 11:56:45 AM9/16/19
to web2py-users
Fabulous. Thanks Massimo!
Reply all
Reply to author
Forward
0 new messages