25 lines
740 B
Python
25 lines
740 B
Python
# _*_ coding: utf-8 _*_
|
|
# @Time :2022/5/29 11:51
|
|
# @Email :508737091@qq.com
|
|
# @Author :qiangyanwen
|
|
# @File :factory.py
|
|
from datetime import datetime
|
|
|
|
|
|
class AutomationResponse(object):
|
|
@staticmethod
|
|
def model_to_dict(obj, *ignore: str):
|
|
data = dict()
|
|
for c in obj.__table__.columns:
|
|
if c.name in ignore:
|
|
continue
|
|
val = getattr(obj, c.name)
|
|
if isinstance(val, datetime):
|
|
data[c.name] = val.strftime("%Y-%m-%d %H:%M:%S")
|
|
else:
|
|
data[c.name] = val
|
|
return data
|
|
|
|
@staticmethod
|
|
def model_to_list(data: list, *ignore: str):
|
|
return [AutomationResponse.model_to_dict(x, *ignore) for x in data] |