发布网友 发布时间:2022-04-26 00:10
共3个回答
懂视网 时间:2022-05-02 18:18
需求:
用户角色,讲师\学员, 用户登陆后根据角色不同,能做的事情不同,分别如下
讲师视图:
学员视图:
表结构:
根据需求先画表结构
程序目录结构:
表结构实例代码:
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 " |