class Person(self.Base, _sav.ValidationMixin): __tablename__ = 'person' id = Column(Integer, primary_key=True) email = Column(Unicode) sav.validates_presence_of('email') sav.validates_email('email')
class Test(self.Base, _sav.ValidationMixin): __tablename__ = 'test' id = Column(Integer, primary_key=True) name = Column(Unicode(30)) email = Column(Unicode) age = Column(Integer) sav.validates_presence_of('name', 'email') sav.validates_email('email')
class Person(Base, ValidationMixin): __tablename__ = 'people' id = sa.Column(sa.Integer, primary_key=True) createdts = sa.Column(sa.DateTime, nullable=False, server_default=sasql.text('CURRENT_TIMESTAMP')) updatedts = sa.Column(sa.DateTime, onupdate=datetime.now) name_first = sa.Column(sa.Unicode(75), nullable=False) name_last = sa.Column(sa.Unicode(75), nullable=False) family_role = sa.Column(sa.Unicode(20), nullable=False) nullable_but_required = sa.Column(sa.Unicode(5)) ROLE_CHOICES = ( ('father', 'Father'), ('mother', 'Mother'), ('child', 'Child'), ) val.validates_constraints(exclude='createdts') val.validates_presence_of('nullable_but_required') val.validates_choices('family_role', ROLE_CHOICES) @before_flush def alter_name(self): if self.name_first == u'randy': self.name_first = u'randall' @before_flush def enforce_president(self): try: self.enforce_president_call_count += 1 except AttributeError: self.enforce_president_call_count = 1 if self.name_last == u'Obama' and self.name_first != 'President': self.add_validation_error('name_first', 'must be "President"') @classmethod def get(cls, oid): return sess.query(cls).get(oid)