diff --git a/common/models/db_models.py b/common/models/db_models.py index 5d3fce23..223709c4 100644 --- a/common/models/db_models.py +++ b/common/models/db_models.py @@ -1,6 +1,8 @@ import enum from datetime import datetime +from decimal import Decimal + from sqlalchemy import Index, Column, BigInteger, String, DateTime, ForeignKey, Integer, Float, FetchedValue, \ TypeDecorator, Boolean from sqlalchemy.ext.declarative import declarative_base @@ -53,6 +55,19 @@ def to_dict(self): dictionary[column.name] = str(attribute) if isinstance(attribute, datetime) else attribute return dictionary + def _make_serializable(self, field): + """ + Given a field, convert to a JSON serializable type + :param field: The field to be converted + :return: The converted field + """ + if isinstance(field, datetime): + return str(field) + elif isinstance(field, Decimal): + return float(field) + else: + return field + def to_nested_dict(self, includes): """ Given related models return a nested dictionary with the child or parent rows nested.