parent
ca2065a94d
commit
ec447e0dc4
8 changed files with 106 additions and 13 deletions
|
|
@ -2,15 +2,24 @@ from django.contrib.auth import get_user_model
|
|||
from rest_framework import serializers
|
||||
|
||||
from uncloud_pay import AMOUNT_DECIMALS, AMOUNT_MAX_DIGITS
|
||||
from uncloud_pay.models import BillingAddress
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
|
||||
balance = serializers.DecimalField(max_digits=AMOUNT_MAX_DIGITS,
|
||||
decimal_places=AMOUNT_DECIMALS)
|
||||
|
||||
class Meta:
|
||||
model = get_user_model()
|
||||
fields = ['username', 'email', 'balance', 'maximum_credit' ]
|
||||
read_only_fields = [ 'username', 'balance', 'maximum_credit' ]
|
||||
fields = read_only_fields + [ 'email', 'primary_billing_address' ]
|
||||
|
||||
def validate(self, data):
|
||||
"""
|
||||
Ensure that the primary billing address belongs to the user
|
||||
"""
|
||||
|
||||
if 'primary_billing_address' in data:
|
||||
if not data['primary_billing_address'].owner == self.instance:
|
||||
raise serializers.ValidationError("Invalid data")
|
||||
|
||||
return data
|
||||
|
||||
class ImportUserSerializer(serializers.Serializer):
|
||||
username = serializers.CharField()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue