Created
July 9, 2019 11:19
-
-
Save akshar-raaj/97282ac170423dbcb563b82759340fd0 to your computer and use it in GitHub Desktop.
DRF users with groups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_users(request): | |
| users = list(User.objects.values(‘first_name’, 'last_name', 'email', ‘id’)) | |
| for user in users: | |
| groups = list(user.groups.values('id', 'name')) | |
| user['groups'] = groups | |
| return JsonResponse(users, safe=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment