You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from schematics import Model
from schematics.types import *
class DummySchema(Model):
from_ = DateType(
serialized_name='from',
required=True
)
to = DateType(
serialized_name='to',
required=True
)
The way to specify additional validators for each field is as follows.
from schematics import Model
from schematics.exceptions import ValidationError
from schematics.types import *
def validate_year_of_to_is_2019(value):
if value.year != 2019:
raise ValidationError('year of to should be 2019.')
class DummySchema(Model):
from_ = DateType(
serialized_name='from',
required=True
)
to = DateType(
serialized_name='to',
required=True,
validators=[validate_year_of_to_is_2019]
)
It would be nice if the field validator could be defined as a decorator.
from schematics import Model
from schematics.exceptions import ValidationError
from schematics.types import *
class DummySchema(Model):
from_ = DateType(
serialized_name='from',
required=True
)
to = DateType(
serialized_name='to',
required=True
)
@to.validator
def validate_year_of_to_is_2019(self, value):
if value.year != 2019:
raise ValidationError('year of to should be 2019.')
The text was updated successfully, but these errors were encountered:
from schematics import Model
from schematics.exceptions import ValidationError
from schematics.types import *
from functools import wraps
def validate_year_of_to_is_2019(func): @wraps(func)
def wrapper(self, value):
if value.year != 2019:
raise ValidationError('year of to should be 2019.')
return func(self, value)
return wrapper
class CustomDateType(DateType):
def init(self, *args, **kwargs):
super().init(*args, **kwargs)
When I define a model like this,
The way to specify additional validators for each field is as follows.
It would be nice if the field validator could be defined as a decorator.
The text was updated successfully, but these errors were encountered: