Ejemplo n.º 1
0
        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')
Ejemplo n.º 2
0
class Person(db.Model, ValidationMixin):
    # auto keys
    id = db.Column(db.Integer, primary_key=True)
    utc_created = db.Column(db.DateTime, nullable=False, default=dt.utcnow())
    utc_updated = db.Column(
        db.DateTime, nullable=False, default=dt.utcnow(), onupdate=dt.utcnow())

    # foreign keys
    currency_id = db.Column(
        db.Integer, db.ForeignKey(
            'commodity.id', onupdate="CASCADE", ondelete="CASCADE"),
        nullable=False)
    currency = db.relationship(
        'Commodity', lazy='joined',
        backref=backref('people', cascade='all, delete'))

    # other keys
    first_name = db.Column(db.Unicode(64), nullable=False)
    last_name = db.Column(db.Unicode(64), nullable=False)
    email = db.Column(db.String(64), unique=True, nullable=False)
    phone = db.Column(db.String(16))
    birth_date = db.Column(db.Date)
    monthly_income = db.Column(db.Float)
    monthly_expenses = db.Column(db.Float)
    marginal_tax_rate = db.Column(db.Float)

    # validation
    val.validates_email('email')
    val.validates_constraints()

    def __repr__(self):
        return ('<Exchange(%r, %r)>' % (self.name, self.email))

    def __str__(self):
        return ('%s: %s' % (self.name, self.email))
Ejemplo n.º 3
0
        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')