Created
April 29, 2014 12:20
-
-
Save danielholmstrom/11398605 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreatedAtMixin(object): | |
"""Adds a read-only column created_at to a table | |
An sqlalchemy.exc.ArgumentError will be raised it someone is trying to set | |
created_at. However, the '_created' column can still be set. | |
""" | |
_created = Column('created_at', DateTime, | |
server_default=text('NOW()'), nullable=False) | |
@hybrid_property | |
def created_at(self): | |
""" Get the column created """ | |
return self._created | |
@created_at.setter | |
def set_created_at(self, created): | |
""" Prevents the column created from being set """ | |
raise ArgumentError('Column created_at is read-only') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment