base.py 893 Bytes
Newer Older
1 2 3 4 5 6 7 8
# -*- encoding: utf-8 -*-
# -----------------------------------------------------------------------------
# @File Name  : base.py
# @Time       : 2020/11/18 下午12:47
# @Author     : X. Peng
# @Email      : acepengxiong@163.com
# @Software   : PyCharm
# -----------------------------------------------------------------------------
pengxiong's avatar
pengxiong committed
9 10
import datetime

赵杰's avatar
赵杰 committed
11
from sqlalchemy.ext.declarative import declarative_base
12
Base = declarative_base()
赵杰's avatar
赵杰 committed
13 14


15 16 17 18 19 20
class BaseModel():
    """."""

    def __init__(self):
        pass

pengxiong's avatar
pengxiong committed
21 22 23 24 25 26 27
    def to_dict(self, allow_field=None):
        all_field = [r.name for r in self.__table__.columns]
        if allow_field:
            allow_field = set(allow_field) & set(allow_field)
        else:
            allow_field = all_field
        return {c: int(getattr(self, c).timestamp()) if isinstance(getattr(self, c), datetime.datetime) else getattr(self, c) for c in allow_field}
28 29