需求:

用户角色,讲师\学员, 用户登陆后根据角色不同,能做的事情不同,分别如下

讲师视图:

  •   管理班级,可创建班级,根据学员qq号把学员加入班级
  •   可创建指定班级的上课纪录,注意一节上课纪录对应多条学员的上课纪录, 即每节课都有整班学员上, 为了纪录每位学员的学习成绩,需在创建每节上课纪录是,同时为这个班的每位学员创建一条上课纪录
  •   为学员批改成绩, 一条一条的手动修改成绩

学员视图:

  • 提交作业
  • 查看作业成绩
  • 一个学员可以同时属于多个班级,就像报了Linux的同时也可以报名Python一样, 所以提交作业时需先选择班级,再选择具体上课的节数
  • 附加:学员可以查看自己的班级成绩排名

表结构:

根据需求先画表结构

程序目录结构:

表结构实例代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from 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
 
 
############创建数据表结构######################3
Base = declarative_base()
 
# 班级与学生的对应关系表
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")),
                          )
 
# 班级与学生的对应关系表
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):
    '''班级和课节对应表'''
    __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):
    "上课记录"
    __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,状态:【%s】,成绩:【%s】\33[0m"%(self.class_m2m_lessons,self.students,self.status,self.score)
 
class Teacher(Base):
    "讲师"
    __tablename__ = "teacher"
    teacher_id = Column(Integer, primary_key=True)
    teacher_name = Column(String(32), nullable=False, unique=True)   #唯一
 
    classes = relationship("Class", secondary=teacher_m2m_class, backref="teachers")
 
    def __repr__(self):
        return "讲师:【%s】"%self.teacher_name
 
class Class(Base):
    "班级"
    __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 "班级名:【%s】"%self.class_name
 
class Student(Base):
    "学生"
    __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 "学生名:【%s】"%self.stu_name
 
class Lesson(Base):
    "课节"
    __tablename__ = "lesson"
    lesson_id = Column(Integer, primary_key=True)
    lesson_name = Column(String(32), nullable=False, unique=True)
 
    def __repr__(self):
        return "节次名:【%s】"%self.lesson_name
 
 
Base.metadata.create_all(engine)

创建学习记录以及修改学生成绩:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def add_studyrecord(self):
        '''添加学习记录'''
        class_name = input("\033[34;0m请输入要添加学习记录的班级名:\033[0m")
        class_obj = self.session.query(Class).filter_by(class_name=class_name).first()
 
        if class_obj and class_obj.teachers[0== self.teacher_obj:  # 输入的班级名存在且在属于当前老师管理
            lesson_name = input("\033[34;0m请输入添加学习记录的课节名(lesson):\033[0m")
            lesson_obj = self.session.query(Lesson).filter_by(lesson_name=lesson_name).first()
            if lesson_obj:                                       # 输入的lesson名字存在
                class_m2m_lesson_obj = self.session.query(Class_m2m_Lesson).filter(Class_m2m_Lesson.class_id == class_obj.class_id). \
                    filter(Class_m2m_Lesson.lesson_id == lesson_obj.lesson_id).first()
                if class_m2m_lesson_obj:                                            # 班级对应的课lesson表数据存在
 
                    study_record_obj = self.session.query(Study_record).filter_by(class_m2m_lesson_id=class_m2m_lesson_obj.id).first()
                    if not study_record_obj:                                                    # 上课记录为创建
                        for student_obj in class_obj.students:
                            status = input("输入学生 %s 的上课状态(yes/no):"%student_obj.stu_name)
                            study_record_new = Study_record(class_m2m_lesson_id=class_m2m_lesson_obj.id,
                                                            stu_id=student_obj.stu_id,
                                                            status=status)
                            self.session.add(study_record_new)
                            self.session.commit()
                    else:
                        print("\33[31;1m系统错误:当前上课记录已经创建\33[0m")
                else:
                     print("\33[31;1m系统错误:当前班级的lesson课节未创建\33[0m")
            else:
                print("\33[31;1m系统错误:lesson未创建\33[0m")
        else:
            print("\33[31;1m输入错误:班级不存在或没有权限管理此班级\33[0m")
 
 
    def modify_scores(self):
        '''修改成绩'''
        class_name = input("\033[34;0m请输入学习记录的班级名:\033[0m")
        class_obj = self.session.query(Class).filter_by(class_name=class_name).first()
 
        if class_obj and class_obj.teachers[0== self.teacher_obj:  # 输入的班级名存在且在属于当前老师管理
            lesson_name = input("\033[34;0m请输入学习记录的课节名(lesson):\033[0m")
            lesson_obj = self.session.query(Lesson).filter_by(lesson_name=lesson_name).first()
 
            if lesson_obj:  # 输入的lesson名字存在
                class_m2m_lesson_obj = self.session.query(Class_m2m_Lesson).filter(
                    Class_m2m_Lesson.class_id == class_obj.class_id). \
                    filter(Class_m2m_Lesson.lesson_id == lesson_obj.lesson_id).first()
 
                if class_m2m_lesson_obj:  # 班级对应的课lesson表数据存在
                    while True:
                        study_record_objs = self.session.query(Study_record).filter(
                                Study_record.class_m2m_lesson_id==class_m2m_lesson_obj.id).all()
                        for obj in  study_record_objs:
                            print(obj)
 
                        student_name = input("\033[34;0m输入要修改成绩的学生名:[Q 退出]\33[0m")
                        if student_name == "q" or student_name == "Q":break
                        student_obj = self.session.query(Student).filter_by(stu_name=student_name).first()
                        if student_obj:
                            study_record_obj = self.session.query(Study_record).filter(
                                Study_record.class_m2m_lesson_id==class_m2m_lesson_obj.id).filter(
                                Study_record.stu_id == student_obj.stu_id).first()
 
                            if study_record_obj:                            # 上课记录存在
                                score = input("\033[34;0m输入修改后的成绩\33[0m")
                                study_record_obj.score= score
                                self.session.commit()
 
                    else:
                        print("\33[31;1m系统错误:当前上课记录已经创建\33[0m")
                else:
                    print("\33[31;1m系统错误:当前班级的lesson课节未创建\33[0m")
            else:
                print("\33[31;1m系统错误:lesson未创建\33[0m")
        else:
            print("\33[31;1m输入错误:班级不存在或没有权限管理此班级\33[0m")

上面的两段代码实现了主要的功能,其他的功能都是套路,都一样。。。。

完整代码地址--》》https://coding.net/u/James_Lian/p/Whaterver/git/tree/master

参考:https://www.cnblogs.com/sean-yao/p/8088186.html

Python开发【项目】:学员管理系统(mysql)的更多相关文章

  1. python开发的学生管理系统

    python开发的学生管理系统(基础版) #定义一个函数,显示可以使用的功能列表给用户 def showInfo(): print("-"*30) print(" 学生管 ...

  2. python项目开发:学员管理系统

    学员管理系统 #需求: 1.用户角色:讲师/学员,登陆后根据角色不同能做的事情不同 2.讲师视图 - 管理班级,可创建班级,根据学员qq号把学员加入班级 - 可创建指定班级的上课纪录,注意一节上课纪录 ...

  3. 吴裕雄--天生自然PythonDjangoWeb企业开发:学员管理系统- 前台

    开发首页 做一个简单的用户提交申请的表单页面. 首先在student/views.py文件中编写下面的代码: # -*- coding: utf-8 -*- from __future__ impor ...

  4. 吴裕雄--天生自然PythonDjangoWeb企业开发:学员管理系统后台

    需求 提供一个学员管理系统,一个前台页面,展示现有学员,并供新学员提交申请,一个后台,能够处理申请. pip install django==1.11.2 创建项目 使用控制台进入到一个目录下,具体是 ...

  5. python开发项目:学生选课系统

    程序要求:1.创建北京.上海两所学校(分析:通过学校类实例化两个学校实例) 2.创建Linux.python.go三个课程,Linux\go在北京开,Linux在上海开(创建Linux.python. ...

  6. Python开发项目:大型模拟战争游戏(外星人入侵)

    外星人入侵 游戏概述: 现在准备用python开始搞一个大型游戏,模拟未来战争,地球人狙击外星人大战(其实就是小蜜蜂游戏2333),玩家控制一个飞船,用子弹歼灭屏幕上空的外星飞船:项目用到了Pygam ...

  7. Python 开发 项目《外星人入侵》

    2019-02-05 本篇心路历程: 本篇是打算记录自己的第一个python项目,也是众人皆知的<外星人入侵项目>,本项目大概500多行.趁着寒假,大概耗时3天吧,把完整代码敲了出来,当然 ...

  8. Python开发程序:学员管理系统(mysql)

    主题:学员管理系统 需求: 用户角色,讲师\学员, 用户登陆后根据角色不同,能做的事情不同,分别如下 讲师视图: 管理班级,可创建班级,根据学员qq号把学员加入班级 可创建指定班级的上课纪录,注意一节 ...

  9. python3开发进阶-Django框架学习前的小项目(一个简单的学员管理系统)

    ''' 自己独立写一个学员管理系统 表结构: 班级表: -id -grade_name 学生表: -id -student_name -grade 关联外键班级表 老师表: -id -teacher_ ...

  10. Python学习(二十七)—— Django和pymysql搭建学员管理系统

    转载自http://www.cnblogs.com/liwenzhou/p/8270250.html 一.学员管理系统 1.项目规划阶段 项目背景 近年来老男孩教育的入学学员数量稳步快速增长,传统的e ...

随机推荐

  1. phpstudy----------如何将phpstudy里面的mysql升级到指定版本,如何升级指定PHP版本

    1.下载指定版本:从官网上下载高版本的 MySQL :https://dev.mysql.com/downloads/file/?id=467269,选的版本是 5.7.17 2.请注意第四部以前是可 ...

  2. 说一说javascript的异步编程

    众所周知javascript是单线程的,它的设计之初是为浏览器设计的GUI编程语言,GUI编程的特性之一是保证UI线程一定不能阻塞,否则体验不佳,甚至界面卡死. 所谓的单线程就是一次只能完成一个任务, ...

  3. crontab定时

    yum install -y vixie-cron --安装定时服务 每分钟更新一次商品crontab -e* * * * * /usr/bin/curl http://test.wadao.com/ ...

  4. 游戏客户端Session的统一管理

    看本系统文章需要些C语言.数据结构和网络基础知识! 说明:由于游戏服务器端会有成千上万的客户端进行连接请求,所以要求我们需要做一些简单的会话管理!如下图 1.简单说明 进行统一的分配和管理,就需要我们 ...

  5. 【题解】Luogu SP1435 PT07X - Vertex Cover

    原题传送门 求树的最小点覆盖,就是一个树形dp 类似于没有上司的舞会 dp的状态为\(f[i][0/1]\),表示i节点是否选择 边界是\(f[x][0]=0\),\(f[x][1]=1\) 转移方程 ...

  6. linux bash tutorial

    bash read-special-keys-in-bash xdotool linux 登录启动顺序

  7. Linux相关代码

    Linux ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---- ...

  8. idea使用svn报错

    第一种情况:idea没有安装svn. 选择file→settings→plugins,在右侧框中搜索"SVN"(有的是subversion),选中搜索出来的东西,然后点击下面的in ...

  9. 深度学习课程笔记(十八)Deep Reinforcement Learning - Part 1 (17/11/27) Lectured by Yun-Nung Chen @ NTU CSIE

    深度学习课程笔记(十八)Deep Reinforcement Learning - Part 1 (17/11/27) Lectured by Yun-Nung Chen @ NTU CSIE 201 ...

  10. [大数据从入门到放弃系列教程]第一个spark分析程序

    [大数据从入门到放弃系列教程]第一个spark分析程序 原文链接:http://www.cnblogs.com/blog5277/p/8580007.html 原文作者:博客园--曲高终和寡 **** ...