Last active
August 29, 2015 13:56
-
-
Save kevinjqiu/9099841 to your computer and use it in GitHub Desktop.
This file contains 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 AppendOnlyModelMeta(DeclarativeMeta): | |
@staticmethod | |
def _get_append_only_attributes(cls): | |
'''A helper method to get a list of append-only attributes | |
declared on the class.''' | |
[...] | |
def __init__(cls, classname, bases, dict_): | |
if hasattr(cls, '__history_class__'): | |
cls._history_fields = cls._get_append_only_attributes(cls) | |
cls._history = relationship( | |
cls.__history_class__, | |
order_by=cls.__history_class__.id.desc()) | |
super(AppendOnlyModelMeta, cls).__init__(classname, bases, dict_) | |
class AppendOnlyModel(Base): | |
'''The base class for all models that support append only storage. | |
Subclasses need to implement '__history_class__' attribute | |
pointing to a History table instance (inherited from HistoryBase) | |
''' | |
__abstract__ = True | |
__metaclass__ = AppendOnlyModelMeta |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment