Created
July 9, 2019 11:14
-
-
Save akshar-raaj/bf2cef55c10ead808dcaa6e7ed66b162 to your computer and use it in GitHub Desktop.
DRF Vanialla view with computed field
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): | |
| 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