You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
775 B
32 lines
775 B
import pycountry
|
|
|
|
from rest_framework import serializers
|
|
|
|
from rest_framework.exceptions import ValidationError
|
|
|
|
from ..models import Provider
|
|
|
|
|
|
class ProviderSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
model = Provider
|
|
fields = '__all__'
|
|
read_only_fields = ('id', 'timestamp')
|
|
|
|
def validate_language(self, value):
|
|
try:
|
|
_ = pycountry.languages.lookup(value)
|
|
except LookupError:
|
|
raise ValidationError(f'Invalid value for language: {value}.')
|
|
|
|
return value
|
|
|
|
def validate_currency(self, value):
|
|
try:
|
|
_ = pycountry.currencies.lookup(value)
|
|
except LookupError:
|
|
raise ValidationError(f'Invalid value for currency: {value}.')
|
|
|
|
return value
|