from sqlalchemy.schema import UniqueConstraint
from sqlalchemy.ext.declarative import declared_attr


class MessageMixIn(object):
    ttime = Column(DateTime)

@declared_attr
def sometable_id(cls):
    return Column(Integer, ForeignKey('sometable.id'))

@declared_attr
def __table_args__(cls):
    return UniqueConstraint('sometable_id', 'ttime'), {}
Повторное использование моделей SQLAlchemy в проектах