def toDict(data) -> dict:
    from sqlalchemy import DateTime, Date

    def dateToStr(date):
        if date is None:
            return None
        return date.strftime("%Y-%m-%d %H:%M:%S")

    def dateOnlyToStr(date):
        if date is None:
            return None
        return date.strftime("%Y-%m-%d")

    result = {}

    # Обрабатываем колонки таблицы с автоматическим определением типа
    for c in data.__table__.columns:
        value = getattr(data, c.name)

        # Проверяем тип колонки
        if isinstance(c.type, DateTime):
            result[c.name] = dateToStr(value)
        elif isinstance(c.type, Date):
            result[c.name] = dateOnlyToStr(value)
        else:
            result[c.name] = value

    # Обрабатываем relationship поля
    for rel in data.__mapper__.relationships.keys():
        related_data = getattr(data, rel)
        if related_data is not None:
            if isinstance(related_data, list):
                result[rel] = [
                    item.toDict() if hasattr(item, "toDict") else str(item)
                    for item in related_data
                ]
            else:
                result[rel] = (
                    related_data.toDict()
                    if hasattr(related_data, "toDict")
                    else str(related_data)
                )

    return result
