Hi Anthony,
Thanks ,but I am getting the following error,
IndexError: list index out of range
group_members = db(db.auth_membership.group_id ==
auth.id_group('user'))._select(db.auth_membership.user_id)
@auth.requires_login()
def companys():
db.company.created_on.readable = True
db.company.created_by.readable = True
db.company.company_name.represent = lambda company_name,row:\
A(company_name,_href=URL('view_company',args=row.id))
query = db(db.company.created_by.belongs(group_members))
grid = SQLFORM.grid(query, orderby=~db.company.created_on,
create=False,details=False,editable=False,
deletable=lambda row:
(row.created_by.belongs(group_members)),
fields =[
db.company.company_name,
db.company.client_type,
db.company.address1,
db.company.address2,
db.company.phone,
db.company.mobile,
db.company.email,
db.company.created_by,
db.company.created_on,
]
)
return locals()
What do I have wrong?
Thanks
On Tuesday, 1 December 2015 03:16:03 UTC+11, Anthony wrote:
>
> 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.