uncloud-mravi/uncloud/uncloud_auth/serializers.py
2020-03-18 14:36:40 +01:00

14 lines
461 B
Python

from django.contrib.auth import get_user_model
from rest_framework import serializers
from uncloud_pay.models import get_balance_for_user
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = get_user_model()
fields = ['username', 'email', 'balance']
# Display current 'balance'
balance = serializers.SerializerMethodField('get_balance')
def get_balance(self, user):
return get_balance_for_user(user)