This commit is contained in:
pycook 2019-11-15 18:03:06 +08:00
parent 332659c1d5
commit f78c3b928b
1 changed files with 8 additions and 3 deletions

View File

@ -10,9 +10,14 @@ from api.lib.exception import CommitException
class FormatMixin(object):
def to_dict(self):
return dict([(k.name, isinstance(getattr(self, k.name), datetime.datetime) and
getattr(self, k.name).strftime('%Y-%m-%d %H:%M:%S')) or
getattr(self, k.name) for k in getattr(self, "__table__").columns])
res = dict()
for k in getattr(self, "__table__").columns:
if not isinstance(getattr(self, k.name), datetime.datetime):
res[k.name] = getattr(self, k.name)
else:
res[k.name] = getattr(self, k.name).strftime('%Y-%m-%d %H:%M:%S')
return res
@classmethod
def get_columns(cls):