On Thursday, December 22, 2016 at 5:13:17 AM UTC+1, antonel...@yottacle.com 
wrote:
>
> Hi,
> in my model I have users who have membership to more groups.
> I am trying to perform a query of users who DO NOT belong to a group; 
> something along these lines:
>
> query = db ((db.auth_user != auth.user.id) & (~(auth.has_membership 
> ("admin", db.auth_user.id))).select (db.auth_user.first_name, 
> db.auth_user.last_name)
>
> The above query does not work, i.e. it retrieves all records except the 
> currently logged in user (which is OK) but ignores the "has_membership" 
> condition. It gives no errors, though...
>
> I know I can perform the select with only the first condition and then 
> loop over the result to remove the users that have membership to group 
> "admin", but I wonder if I can have the result in a single query.
>
> Thanks!
>

== EDIT ==

I have found a way to get what I need:

    users = db (
                (db.auth_user.id != userid)
                ).select (db.auth_user.id,
                          db.auth_user.first_name,
                          db.auth_user.last_name,
                          db.auth_user.email,
                          distinct = True).exclude (lambda row: not 
auth.has_membership ("admin", row.id))
 
Not sure how efficient it is but it works.

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