You can make it an emailinternal column that you cannot write to in ORM.
class Person(Base):
__tablename__ = 'person'
id = Column(Integer, primary_key=True)
_email = Column("email", String)
@hybrid_property
def email(self):
return self._email
Unable to write:
>>> p = Person(email="foo@bar.com")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 4, in __init__
File "/Library/Python/2.7/site-packages/sqlalchemy/orm/state.py", line 306, in _initialize_instance
manager.dispatch.init_failure(self, args, kwargs)
File "/Library/Python/2.7/site-packages/sqlalchemy/util/langhelpers.py", line 60, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "/Library/Python/2.7/site-packages/sqlalchemy/orm/state.py", line 303, in _initialize_instance
return manager.original_init(*mixed[1:], **kwargs)
File "/Library/Python/2.7/site-packages/sqlalchemy/ext/declarative/base.py", line 649, in _declarative_constructor
setattr(self, k, kwargs[k])
AttributeError: can't set attribute
source
share