[Fixed]-Using objects.get or objects.filter to obtain specific groups to use in form filter

1👍

How about this QuerySet API Field Lookups using “in”.

 request.user.groups.get(name__in=['Client1' ,'Client2' , 'Client3' , 'Client4'])

0👍

Your query boils down to:

request.user.groups.get(name='Client1')

This is because the result of:

'Client1' or 'Client2' or 'Client3' or 'Client4'

Will always be 'Client1'.

If you just want to get all the groups the current user belongs to:

user_groups = request.user.group_set.all()

If your user can only belong to one group, then use:

user_group = request.user.group

Leave a comment