SQLAlchemy docs explain how to use the @validates decorator to add model validation.
from sqlalchemy.orm import validates class EmailAddress(Base): __tablename__ = 'address' id = Column(Integer, primary_key=True) email = Column(String) @validates('email') def validate_email(self, key, address): assert '@' in address return address
I have a model with two dates, and I would like to create a validator that ensures that one date is always greater than the second. Is it possible to create a model level validator? If so, what is the syntax?
source share