django-phone-field and rest framework: not a valid number

167 Views Asked by At

I'd like to use django-phone-field together with rest-framework. I've configured a simple model:

from phonenumber_field.modelfields import PhoneNumberField

class UserProfile(models.Model):
    user = models.OneToOneField(CustomUser, on_delete=models.CASCADE)
    phone = PhoneNumberField(null=True, blank=True)

As well es as a modelSerializer:

from phonenumber_field.serializerfields import PhoneNumberField

 class UserProfileSerializer(CountryFieldMixin, serializers.ModelSerializer):

    phone = PhoneNumberField(required=False)
    user = serializers.StringRelatedField(read_only=True)

    class Meta:
        model = UserProfile
        fields ="__all__"

I'd like to be able to use international numbers. The problem is, that depending on the country-prefix used, I'm getting a repsonse to enter a valid number. The examples from the django-phone-field documentation work, using a prefix +1 . The prefix for France and Germany work as well. However, other countries I've tried don't work, e.g. CZ: +420 . But maybe I'm using the module wrong altogether.

Does someone know, how to use django-phone-field + rest-framework with international numbers?

Thanks a lot. -)

0

There are 0 best solutions below