Reoraganized project

This commit is contained in:
ITQ
2024-03-02 13:22:29 +03:00
parent bcdcfaf7f2
commit ed687650ba
27 changed files with 58 additions and 45 deletions
+17
View File
@@ -0,0 +1,17 @@
from django.core.exceptions import ValidationError
from django.core.validators import BaseValidator
from django.utils.deconstruct import deconstructible
from api.countries.models import Country
@deconstructible
class CountryCodeValidator(BaseValidator):
def __init__(self, message=None):
self.message = message or "There is no such country"
def __call__(self, value):
try:
Country.objects.get(alpha2=value)
except Country.DoesNotExist:
raise ValidationError(self.message) from None