Created
August 29, 2014 11:56
-
-
Save jap/aee0d532e456f3ca74bc 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
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