Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jap/aee0d532e456f3ca74bc to your computer and use it in GitHub Desktop.
Save jap/aee0d532e456f3ca74bc to your computer and use it in GitHub Desktop.
Base = declarative_base()
def __Base__repr__(self):
"""A usable repr for objects from the declarative_base hierarchy"""
atts = []
for key in self.__table__.c.keys():
if key in self.__dict__:
if not (hasattr(self.__table__.c.get(key).default, 'arg') and
getattr(self.__table__.c.get(key).default, 'arg') == getattr(self, key)):
atts.append( (key, getattr(self, key)) )
return self.__class__.__name__ + '(' + ', '.join(x[0] + '=' + repr(x[1]) for x in atts) + ')'
Base.__repr__ = __Base__repr__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment