Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save akshar-raaj/bf2cef55c10ead808dcaa6e7ed66b162 to your computer and use it in GitHub Desktop.
DRF Vanialla view with computed field
def get_users(request):
FIELDS = ['first_name', 'last_name', 'last_login', 'phone', 'photo', 'email', 'id']
users = list(User.objects.values(*FIELDS))
for user in users:
groups = list(user.groups.values('id', 'name'))
user['groups'] = groups
user['is_birthday_soon'] = user.is_birthday_in_this_month()
return JsonResponse(users, safe=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment