usermod/Model/UserModel.py

33 lines
1.4 KiB
Python
Raw Normal View History

2023-02-07 08:48:41 +08:00
import uuid
from sqlalchemy.orm import relationship
from sqlalchemy import Column, String, Boolean, ForeignKey, Enum, Text, DateTime, func
from Utils.SqlAlchemyUtils import Base
class User(Base):
__tablename__ = "USER_TABLE"
id = Column(String(8), primary_key=True, default=lambda: uuid.uuid4().hex, comment="用户ID")
email = Column(String(64), unique=True, index=True, comment="邮箱")
password = Column(String(255))
name = Column(String(32), index=True, nullable=False, comment="用户名")
avatar = Column(String(255), comment="头像路径")
role = Column(Enum('admin', 'normal'), default="normal", comment="角色")
department = Column(Text, comment="部门")
post = Column(Text, comment="职务")
disable = Column(Boolean, default=False, comment="禁用时间")
auth_data = Column(Text, comment="权限数据")
create_time = Column(DateTime, server_default=func.now(), comment='创建时间')
update_time = Column(DateTime, server_default=func.now(), onupdate=func.now(), comment='修改时间')
def to_dict(self):
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
def as_info(self):
org_info = self.to_dict()
info = org_info.copy()
for key in org_info:
if key not in ["password","create_time","update_time"]:
info[key] = org_info[key]
return info