Skip to content

Instantly share code, notes, and snippets.

@kevinjqiu
Last active August 29, 2015 13:56
Show Gist options
  • Save kevinjqiu/9099841 to your computer and use it in GitHub Desktop.
Save kevinjqiu/9099841 to your computer and use it in GitHub Desktop.
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