From c2dd3d9c1b59c607ea466b91da27af11b99303a5 Mon Sep 17 00:00:00 2001 From: Dewi Roberts Date: Fri, 30 May 2025 14:45:33 +0100 Subject: [PATCH] website/docs: update user ref doc with parent group example (#14779) * Adds example * Update website/docs/users-sources/user/user_ref.mdx Co-authored-by: Tana M Berry Signed-off-by: Dewi Roberts * Small updates --------- Signed-off-by: Dewi Roberts Co-authored-by: Tana M Berry --- website/docs/users-sources/user/user_ref.mdx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/website/docs/users-sources/user/user_ref.mdx b/website/docs/users-sources/user/user_ref.mdx index 134139a7b2..c16348b8a0 100644 --- a/website/docs/users-sources/user/user_ref.mdx +++ b/website/docs/users-sources/user/user_ref.mdx @@ -25,7 +25,7 @@ These are examples of how User objects can be used within Policies and Property ### List a user's group memberships -Use the following example to list all groups that a User object is a member of: +Use the following example to list all groups that a user object is a member of: ```python for group in user.ak_groups.all(): @@ -34,12 +34,20 @@ for group in user.ak_groups.all(): ### List a user's group memberships and filter based on group name -Use the following example to list groups that a User object is a member of, but filter based on group name: +Use the following example to list groups that a user object is a member of, but filter based on group name: ```python user.ak_groups.filter(name__startswith='test') ``` +### List a user's group memberships including parent groups + +Use the following example to list all groups that a user object is a member of, including parent groups: + +```python +groups = [group.name for group in request.user.all_groups()] +``` + :::info For Django field lookups, see the [Django documentation](https://docs.djangoproject.com/en/stable/ref/models/querysets/#id4). :::