90👍
✅
The following query solved my problem.
User.objects.filter(groups__name='Staff')
Thanks to @SardorbekImomaliev for figuring it out.
10👍
This query allows you to find users by group id rather than by group name:
group = Group.objects.get(id=group_id)
users = group.user_set.all()
Here’s a query that lets you search by group name:
users = User.objects.filter(groups_name='group_name')
- [Django]-How to test custom django-admin commands
- [Django]-"gettext()" vs "gettext_lazy()" in Django
- [Django]-Paginate relationship in Django REST Framework?
Source:stackexchange.com