class Grade(db.Model): id = db.Column(db.Integer, primary_key=True) number = db.Column(db.Integer, unique=False, nullable=False) letter = db.Column(db.String(1), unique=False, nullable=False) school_id = db.Column(db.Integer, db.ForeignKey("school.id"), nullable=False)
class CallSchedule(db.Model): id = db.Column(db.Integer, primary_key=True) school_id = db.Column(db.Integer, db.ForeignKey("school.id"), nullable=False) subject_number = db.Column(db.Integer, nullable=False, unique=False) start = db.Column(db.String(5), nullable=False, unique=False) end = db.Column(db.String(5), nullable=False, unique=False)
class Request(db.Model): id = db.Column(db.Integer, primary_key=True) region = db.Column(db.String(50), unique=False, nullable=False) city = db.Column(db.String(50), unique=False, nullable=False) school = db.Column(db.String(80), unique=False, nullable=False) name = db.Column(db.String(30), unique=False, nullable=False) surname = db.Column(db.String(30), unique=False, nullable=False) patronymic = db.Column(db.String(30), unique=False, nullable=False) email = db.Column(db.String(50), unique=True, nullable=False) password_hash = db.Column(db.String(128), unique=True, nullable=False)
class Student(User, db.Model): grade_id = db.Column(db.Integer, db.ForeignKey("grade.id"), nullable=False) grade = db.relationship("Grade", backref=db.backref("students", lazy=True)) parent_id = db.Column(db.Integer, db.ForeignKey("parent.id"), nullable=False) parent = db.relationship("Parent", backref=db.backref("children"), lazy=True) school_id = db.Column(db.Integer, db.ForeignKey("school.id"), nullable=False) school = db.relationship("School", backref=db.backref("students"), lazy=True)
class Teacher(User, db.Model): school_id = db.Column(db.Integer, db.ForeignKey("school.id"), nullable=False) school = db.relationship("School", backref=db.backref("teachers"), lazy=True) homeroom_grade_id = db.Column(db.Integer, db.ForeignKey("grade.id"), nullable=True) homeroom_grade = db.relationship("Grade", backref=db.backref("homeroom_teacher"), lazy=True) subjects = db.relationship("Subject", secondary=teacher_subjects, backref=db.backref("teachers", lazy=True))
class Parent(User, db.Model): school_id = db.Column(db.Integer, db.ForeignKey("school.id"), nullable=False) school = db.relationship("School", backref=db.backref("parents"), lazy=True)
class User: id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30), unique=False, nullable=False) surname = db.Column(db.String(30), unique=False, nullable=False) patronymic = db.Column(db.String(30), unique=False, nullable=False) email = db.Column(db.String(50), unique=True, nullable=False) login = db.Column(db.String(31), unique=True, nullable=False) password_hash = db.Column(db.String(128), unique=False, nullable=False) throwaway_password = db.Column(db.Boolean, default=True)
class Message(db.Model): id = db.Column(db.Integer, primary_key=True) sender_id = db.Column(db.Integer, nullable=False, unique=False) sender_role = db.Column(db.String(11), nullable=False, unique=False) recipient_role = db.Column(db.String(11), nullable=False, unique=False) recipient_id = db.Column(db.Integer, nullable=False, unique=False) text = db.Column(db.Text, unique=False, nullable=False) date = db.Column(db.DateTime, nullable=False, default=lambda: datetime.now()) read = db.Column(db.Boolean, nullable=False, default=False)
class Announcement(db.Model): id = db.Column(db.Integer, primary_key=True) school_id = db.Column(db.Integer, db.ForeignKey("school.id"), nullable=False) author_id = db.Column(db.Integer, nullable=False, unique=False) author_role = db.Column(db.String(11), nullable=False, unique=False) header = db.Column(db.String(80), nullable=False, unique=False) text = db.Column(db.Text, unique=False, nullable=False) for_users = db.Column(db.String(34), unique=False, nullable=False) date = db.Column(db.DateTime, nullable=False, default=lambda: datetime.now())
class SubjectDescription(db.Model): id = db.Column(db.Integer, primary_key=True) subject_id = db.Column(db.Integer, db.ForeignKey("subject.id"), nullable=False) school_id = db.Column(db.Integer, db.ForeignKey("school.id"), nullable=False) date = db.Column(db.DateTime, nullable=False) grade_id = db.Column(db.Integer, db.ForeignKey("grade.id"), nullable=False) grade = db.relationship("Grade", backref="subject_descriptions", lazy=True) subject = db.relationship("Subject", backref="subject_descriptions", lazy=True) theme = db.Column(db.Text, nullable=False, unique=False) homework = db.Column(db.Text, nullable=False, unique=False)
class Marks(db.Model): id = db.Column(db.Integer, primary_key=True) mark = db.Column(db.Integer, nullable=True, unique=False) attendance = db.Column(db.Text, nullable=True, unique=False) subject_id = db.Column(db.Integer, db.ForeignKey("subject_description.id"), nullable=False) student_id = db.Column(db.Integer, db.ForeignKey("student.id"), nullable=False) school_id = db.Column(db.Integer, db.ForeignKey("school.id"), nullable=False) subject = db.relationship("SubjectDescription", backref="marks", lazy=True) student = db.relationship("Student", backref="marks", lazy=True)
class Schedule(db.Model): id = db.Column(db.Integer, primary_key=True) day = db.Column(db.Integer, unique=False, nullable=False) subject_number = db.Column(db.Integer, unique=False, nullable=False) subject_id = db.Column(db.Integer, db.ForeignKey("subject.id"), nullable=False) subject = db.relationship("Subject", backref="schedule", lazy=True) school_id = db.Column(db.Integer, db.ForeignKey("school.id"), nullable=False) teacher_id = db.Column(db.Integer, db.ForeignKey("teacher.id"), nullable=False) teacher = db.relationship("Teacher", backref=db.backref("schedule"), lazy=True) grade_id = db.Column(db.Integer, db.ForeignKey("grade.id"), nullable=False) grade = db.relationship("Grade", backref="subjects", lazy=True)
class Subject(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(25), unique=False, nullable=False) school_id = db.Column(db.Integer, db.ForeignKey("school.id"), nullable=False)
class School(db.Model): id = db.Column(db.Integer, primary_key=True) region = db.Column(db.String(50), unique=False, nullable=False) city = db.Column(db.String(50), unique=False, nullable=False) school = db.Column(db.String(80), unique=False, nullable=False)
from okayjournal.app import db from datetime import datetime from werkzeug.security import generate_password_hash # Many-to-Many relationships teacher_subjects = db.Table( "teacher_subjects", db.Column("teacher_id", db.Integer, db.ForeignKey("teacher.id")), db.Column("subject_id", db.Integer, db.ForeignKey("subject.id")), ) class User: id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30), unique=False, nullable=False) surname = db.Column(db.String(30), unique=False, nullable=False) patronymic = db.Column(db.String(30), unique=False, nullable=False) email = db.Column(db.String(50), unique=True, nullable=False) login = db.Column(db.String(31), unique=True, nullable=False) password_hash = db.Column(db.String(128), unique=False, nullable=False) throwaway_password = db.Column(db.Boolean, default=True) class SystemAdmin(User, db.Model): pass class Parent(User, db.Model): school_id = db.Column(db.Integer, db.ForeignKey("school.id"),