#!/usr/bin/env python # -*- coding: utf-8 -*- import datetime from sqlalchemy import Column, Integer, String, BOOLEAN, DateTime, UniqueConstraint from db.base import Base class School(Base): id = Column(Integer, primary_key=True, autoincrement=True) name = Column(String(100), nullable=False, comment="学校名称") area_code = Column(String(100), nullable=False, comment="所在区域code,使用,分隔") area_name = Column(String(100), nullable=False, comment="所在区域,如:四川省,成都市,双流区") category = Column(Integer, default=0, comment="学校类型,0:小学,1:初中,2:高中,3:大学") contact_name = Column(String(20), nullable=False, comment="联系人") contact_phone = Column(String(20), default="", comment="联系人电话") is_active = Column(BOOLEAN(), default=True) creator_id = Column(Integer, comment="创建人ID") creator_name = Column(String(32), comment="创建人名称") created_at = Column(DateTime, default=datetime.datetime.now) editor_id = Column(Integer, comment="最后编辑人ID") editor_name = Column(String(32), comment="最后编辑人名称") updated_at = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now) __table_args__ = (UniqueConstraint("name", name="uix_school_name"),) class SchoolGrade(Base): id = Column(Integer, primary_key=True, autoincrement=True) name = Column(String(20), nullable=False, comment="年级名称") school_id = Column(Integer, nullable=False, comment="所属学校") teacher_amount = Column(Integer, default=0, comment="教师人数") student_amount = Column(Integer, default=0, comment="学生人数") __table_args__ = (UniqueConstraint("name", "school_id", name="uix_name_school_id"),) class SchoolClass(Base): id = Column(Integer, primary_key=True, autoincrement=True) name = Column(String(20), nullable=False, comment="班级名称") school_id = Column(Integer, nullable=False, comment="所属学校") school_name = Column(String(100), nullable=False, comment="学校名称") grade_id = Column(Integer, nullable=False, comment="所属年级") grade_name = Column(String(20), nullable=False, comment="年级名称") teacher_amount = Column(Integer, default=0, comment="教师人数") student_amount = Column(Integer, default=0, comment="学生人数") creator_id = Column(Integer, comment="创建人ID") creator_name = Column(String(32), comment="创建人名称") created_at = Column(DateTime, default=datetime.datetime.now) editor_id = Column(Integer, comment="最后编辑人ID") editor_name = Column(String(32), comment="最后编辑人名称") updated_at = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now) __table_args__ = (UniqueConstraint("school_id", "grade_id", "name", name="uix_school_id_grade_id_name"),) # 学制列表 class SchoolSystem(Base): id = Column(Integer, primary_key=True, autoincrement=True) name = Column(String(20), nullable=False, comment="学制名称") grades = Column(String(100), nullable=False, comment="年级列表,逗号分隔")