Skip to content

Instantly share code, notes, and snippets.

@akshar-raaj
Created July 9, 2019 11:19
Show Gist options
  • Select an option

  • Save akshar-raaj/97282ac170423dbcb563b82759340fd0 to your computer and use it in GitHub Desktop.

Select an option

Save akshar-raaj/97282ac170423dbcb563b82759340fd0 to your computer and use it in GitHub Desktop.
DRF users with groups
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