mirror of
https://gitea.bearcatlog.com/Bryant/chassis
synced 2025-01-18 18:25:21 +08:00
add chassis utils
This commit is contained in:
parent
86ed13eb7b
commit
670442f9ea
14
chassis/utils.py
Normal file
14
chassis/utils.py
Normal file
@ -0,0 +1,14 @@
|
||||
from datetime import datetime
|
||||
from sqlalchemy.orm import class_mapper
|
||||
|
||||
|
||||
def model_to_dict(model):
|
||||
if not model:
|
||||
return
|
||||
model_dict = {}
|
||||
for key, column in class_mapper(model.__class__).c.items():
|
||||
if isinstance(getattr(model, key), datetime):
|
||||
model_dict[column.name] = str(getattr(model, key))
|
||||
else:
|
||||
model_dict[column.name] = getattr(model, key, None)
|
||||
return model_dict
|
Loading…
Reference in New Issue
Block a user