fix: phone representation to string

This commit is contained in:
Bai
2026-03-03 17:33:06 +08:00
committed by feng626
parent b028fec6d1
commit 665c5e8134

View File

@@ -409,7 +409,7 @@ class PhoneField(serializers.CharField):
def to_representation(self, value):
try:
phone = phonenumbers.parse(value, 'CN')
value = {'code': '+%s' % phone.country_code, 'phone': phone.national_number}
value = {'code': '+%s' % phone.country_code, 'phone': str(phone.national_number)}
except phonenumbers.NumberParseException:
value = {'code': '+86', 'phone': value}
return value