Are you saying you want to limit the query to records created by members of
a specific auth_group? Assuming you have stored the auth_user IDs in
something like a "created_by" field, you could do:
group_members = db(db.auth_membership.group_id ==
auth.id_group('my role'))._select(db.auth_membership.
user_id)
rows = db(db.mytable.created_by.belongs(group_members)).select()
group_members is defined with ._select rather than .select so it simply
generates the SQL without running the query. The SQL is then used to create
a nested select with the .belongs expression in the next line. This could
also be done in a single query with a join, but then you would have to
refer to all fields with row.tablename.fieldname syntax rather than the
simpler row.fieldname syntax (and also explicitly exclude fields from
db.auth_membership, which you don't really need).
Anthony
On Monday, November 30, 2015 at 3:18:54 AM UTC-5, Anthony Smith wrote:
>
> Hi all
>
> I know auth.requires_login can be used, also auth.requires_has membership.
>
> If I want to query the records created by a group can this be done.
>
> I want to be able to have certain groups to be only able to query certain
> record of the same table.
>
> Cheers
>
> Anthony
>
--
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].
For more options, visit https://groups.google.com/d/optout.