def __setattr__(cls, key, value): if '__mapper__' in cls.__dict__: if isinstance(value, Column): _undefer_column_name(key, value) cls.__table__.append_column(value) cls.__mapper__.add_property(key, value) elif isinstance(value, MapperProperty): cls.__mapper__.add_property(key, _deferred_relation(cls, value)) else: MetaHasTraits.__setattr__(cls, key, value) else: MetaHasTraits.__setattr__(cls, key, value)
def __init__(cls, classname, bases, dict_): if '_decl_class_registry' in cls.__dict__: return MetaHasTraits.__init__(cls, classname, bases, dict_) # create sql columns from flagged traits if '__class_traits__' in cls.__dict__: traits = cls.__dict__['__class_traits__'] for key, trait in traits.items(): if getattr( trait, 'sqldb' ): args = getattr( trait, 'col_args' ) or () kwargs = getattr( trait, 'col_kwargs' ) or {} if 'name' not in kwargs: kwargs['name'] = key if 'type_' not in kwargs: kwargs['type_'] = eval(TRAIT_MAPPING[type(trait.trait_type)]) c = Column(*args, **kwargs) dict_[key] = c _as_declarative(cls, classname, dict_) return MetaHasTraits.__init__(cls, classname, bases, dict_)