baodan/api/insurance/models/department.py

29 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""部门/分组模型。"""
from sqlalchemy import Column, Integer, String, Text, TIMESTAMP, func
from insurance.db.compat import db
class Department(db.Model):
"""部门/分组表。"""
__tablename__ = "insurance_departments"
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(128), nullable=False, comment="部门名称")
code = Column(String(64), unique=True, nullable=False, comment="部门编码")
parent_id = Column(Integer, default=0, comment="上级部门ID0表示顶级")
description = Column(String(256), default="", comment="部门描述")
sort_order = Column(Integer, default=0, comment="排序")
created_at = Column(TIMESTAMP, server_default=func.now())
updated_at = Column(TIMESTAMP, server_default=func.now(), onupdate=func.now())
def to_dict(self):
return {
"id": self.id,
"name": self.name,
"code": self.code,
"parent_id": self.parent_id,
"description": self.description,
"sort_order": self.sort_order,
"created_at": str(self.created_at) if self.created_at else None,
}