-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
31 lines (24 loc) · 1.2 KB
/
models.py
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
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Course(db.Model):
course_id = db.Column(db.Integer, primary_key=True)
course_name = db.Column(db.String, nullable=False)
course_code = db.Column(db.String, unique=True, nullable=False)
course_description = db.Column(db.String)
students = db.relationship("Student", secondary="enrollment", back_populates='courses')
def __repr__(self):
return "<Course %r>" % self.course_code
class Student(db.Model):
student_id = db.Column(db.Integer, primary_key=True)
roll_number = db.Column(db.String, unique=True, nullable=False)
first_name = db.Column(db.String, nullable=False)
last_name = db.Column(db.String)
courses = db.relationship('Course', secondary="enrollment", back_populates='students')
def __repr__(self):
return '<Student %r>' % self.roll_number
class Enrollment(db.Model):
enrollment_id = db.Column(db.Integer, primary_key=True)
student_id = db.Column(db.Integer, db.ForeignKey('student.student_id'), nullable=False)
course_id = db.Column(db.Integer, db.ForeignKey('course.course_id'), nullable=False)
def __repr__(self):
return "<Enrollment %r>" % self.enrollment_id