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 <tanamarieberry@yahoo.com>
Signed-off-by: Dewi Roberts <dewi@goauthentik.io>

* Small updates

---------

Signed-off-by: Dewi Roberts <dewi@goauthentik.io>
Co-authored-by: Tana M Berry <tanamarieberry@yahoo.com>
This commit is contained in:
Dewi Roberts
2025-05-30 14:45:33 +01:00
committed by GitHub
parent 42302d3187
commit c2dd3d9c1b

View File

@ -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).
:::