Theme: Student Management System
Demand:
User roles, lecturers, trainees, users can do different things according to their roles after login, as follows
Lecturer View:
- Management class, can create a class, according to the qq number of students to join the class
- A class record can be created for a given class. Note that one class record corresponds to several students'class records. That is to say, each class has a whole class. In order to record each student's academic performance, it is necessary to create a class record for each class. At the same time, it is necessary to create a class record for each student in this class.
- Manual revision of grades one by one for students
Student View:
- Submit homework
- Check homework results
- A student can belong to more than one class at the same time, just like registering for Linux or Python at the same time, so when submitting homework, you need to select the class first, and then choose the number of specific classes.
- Additional: Students can view their own class rankings
Table structure:
Draw table structure first according to requirement
Program directory structure:
Table structure instance code:
Create a table structurefrom sqlalchemy import String,Column,Integer,ForeignKey,DATE,Table from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import relationship from conf.settings import engine ############Create a data table structure######################3 Base = declarative_base() # Table of Corresponding Relations between Classes and Students teacher_m2m_class = Table("teacher_m2m_class",Base.metadata, Column("teacher_id", Integer, ForeignKey("teacher.teacher_id")), Column("class_id", Integer, ForeignKey("class.class_id")), ) # Table of Corresponding Relations between Classes and Students class_m2m_student = Table("class_m2m_student",Base.metadata, Column("class_id",Integer,ForeignKey("class.class_id")), Column("stu_id", Integer, ForeignKey("student.stu_id")), ) class Class_m2m_Lesson(Base): '''Class and Session Correspondence Table''' __tablename__ = "class_m2m_lesson" id = Column(Integer, primary_key=True) class_id = Column(Integer,ForeignKey("class.class_id")) lesson_id = Column(Integer, ForeignKey("lesson.lesson_id")) classes = relationship("Class",backref="class_m2m_lessons") lessons = relationship("Lesson", backref="class_m2m_lessons") def __repr__(self): return "%s %s" % (self.classes,self.lessons) class Study_record(Base): "Class record" __tablename__ = "study_record" id = Column(Integer,primary_key=True) class_m2m_lesson_id = Column(Integer,ForeignKey("class_m2m_lesson.id")) stu_id = Column(Integer, ForeignKey("student.stu_id")) status = Column(String(32),nullable=False) score = Column(Integer,nullable=True) class_m2m_lessons = relationship("Class_m2m_Lesson",backref="my_study_record") students = relationship("Student", backref="my_study_record") def __repr__(self): return "\033[35;0m%s,%s,Status:%s],Results:%s]\33[0m"%(self.class_m2m_lessons,self.students,self.status,self.score) class Teacher(Base): "lecturer" __tablename__ = "teacher" teacher_id = Column(Integer, primary_key=True) teacher_name = Column(String(32), nullable=False, unique=True) #Only classes = relationship("Class", secondary=teacher_m2m_class, backref="teachers") def __repr__(self): return "Lecturer:%s]"%self.teacher_name class Class(Base): "class" __tablename__ ="class" class_id = Column(Integer, primary_key=True) class_name = Column(String(32), nullable=False,unique=True) course = Column(String(32), nullable=False) students = relationship("Student",secondary=class_m2m_student,backref="classes") def __repr__(self): return "Class name: [%s]"%self.class_name class Student(Base): "Student" __tablename__ ="student" stu_id = Column(Integer, primary_key=True) stu_name = Column(String(32), nullable=False, unique=True) QQ = Column(Integer(), nullable=False) def __repr__(self): return "Student name: [%s]"%self.stu_name class Lesson(Base): "Class day" __tablename__ = "lesson" lesson_id = Column(Integer, primary_key=True) lesson_name = Column(String(32), nullable=False, unique=True) def __repr__(self): return "Section Name: [%s]"%self.lesson_name Base.metadata.create_all(engine)