perf: 优化 phone

pull/10718/head
ibuler 1 year ago
parent a3d32c901d
commit fca3936a79

@ -214,8 +214,11 @@ class BitChoicesField(TreeChoicesField):
class PhoneField(serializers.CharField):
def to_representation(self, value):
if value:
phone = phonenumbers.parse(value, 'CN')
value = {'code': '+%s' % phone.country_code, 'phone': phone.national_number}
try:
phone = phonenumbers.parse(value, 'CN')
value = {'code': '+%s' % phone.country_code, 'phone': phone.national_number}
except phonenumbers.NumberParseException:
value = {'code': '+86', 'phone': value}
return value

Loading…
Cancel
Save