retrieve a list of users added to two different groups?

42 views
Skip to first unread message

micah jatta

unread,
Apr 7, 2019, 6:49:35 PM4/7/19
to web2py-developers
I would like to know to retrieve a list users added to two different groups. I have two groups named "manager" and "assistant".

Dave S

unread,
Apr 30, 2019, 5:30:15 AM4/30/19
to web2py-d...@googlegroups.com


On Sunday, April 7, 2019 at 3:49:35 PM UTC-7, micah jatta wrote:
I would like to know to retrieve a list users added to two different groups. I have two groups named "manager" and "assistant"

This is really a question for web2py-users, but assuming that what you wanted was all the users who were in both "manager" and  "assistant", it would be something like

rows = db((db.auth_membership == mgr_grp_id) && \
   
(db.auth_membership.group_id == asst_grp_id)).select(db.auth_membership.user_id)


The schema for auth_membership has 2 foreign keys (both fields are of type "references"), so you need to look in the referenced tables to interpret the values.  You could do a join with auth_user to get names or email, for instance.  (I'd get the desired group ids in a separate query, just to keep things readable.--

mgr_grp_id = db(db.auth_group.role == "manager").select().first().id


for instance)

/dps

 
Reply all
Reply to author
Forward
0 new messages