Better validation for phone number in billing info

This commit is contained in:
thomas girod
2024-09-27 22:35:03 +02:00
parent d29a5cdb44
commit 1b1284d3d0
8 changed files with 89 additions and 7 deletions

View File

@ -1,6 +1,11 @@
from typing import Annotated
from ninja import ModelSchema, Schema
from pydantic import Field, NonNegativeInt, PositiveInt, TypeAdapter
# from phonenumber_field.phonenumber import PhoneNumber
from pydantic_extra_types.phone_numbers import PhoneNumber, PhoneNumberValidator
from counter.models import BillingInfo
@ -35,4 +40,4 @@ class BillingInfoSchema(ModelSchema):
# for reasons described in the model, BillingInfo.phone_number
# in nullable, but null values shouldn't be actually allowed,
# so we force the field to be required
phone_number: str
phone_number: Annotated[PhoneNumber, PhoneNumberValidator(default_region="FR")]