示例#1
0
class Employee(db.Model):
    """Employee model for SQLAlchemy"""
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(45))
    department_id = db.Column(
        db.Integer,
        db.ForeignKey('department.id', onupdate='CASCADE', ondelete='CASCADE'))
    date_of_birthday = db.Column(db.Date)
    salary = db.Column(db.DECIMAL)

    def __eq__(self, other):
        """
        Compares employees
        :param Department other: compare with this employee
        :return: result of comparing
        :rtype: bool
        """
        if (self.id == other.id) and (self.name == self.name) and (self.department_id == other.department_id) and \
                (self.date_of_birthday == other.date_of_birthday) and (self.salary == other.salary):
            return True
        return False

    def __hash__(self):
        return self.id

    def __repr__(self):
        return f'<Employee> name = {self.name}'
示例#2
0
class Statement(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(255))
    date = db.Column(db.Date)
    students = db.relationship('Student',
                               secondary=statements,
                               backref=db.backref('statements',
                                                  lazy='dynamic'))
示例#3
0
class Department(db.Model):
    """Department model for SQLAlchemy"""
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(45))
    employees = db.relationship('Employee', backref='department')

    def __eq__(self, other):
        """
        Compares departments
        :param Department other: compare with this department
        :return: result of comparing
        :rtype: bool
        """
        if (self.id == other.id) and (self.name
                                      == other.name) and (self.employees
                                                          == other.employees):
            return True
        return False

    def __hash__(self):
        return self.id

    def __repr__(self):
        return f'<Department id={self.id} + {self.name} + {self.employees}>'
示例#4
0
class Student_mark(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    subject = db.Column(db.String(255), nullable=False)
    mark = db.Column(db.Integer, nullable=False)
    student_id = db.Column(db.Integer, db.ForeignKey('student.id'))
示例#5
0
class Student(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    marks = db.relationship('Student_mark', backref='student', lazy=True)
    group = db.Column(db.String(60), nullable=False)
示例#6
0
from rest.api import db

statements = db.Table(
    'statements',
    db.Column('statement_id', db.Integer, db.ForeignKey('statement.id')),
    db.Column('student_id', db.Integer, db.ForeignKey('student.id')))


class Statement(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(255))
    date = db.Column(db.Date)
    students = db.relationship('Student',
                               secondary=statements,
                               backref=db.backref('statements',
                                                  lazy='dynamic'))


class Student(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    marks = db.relationship('Student_mark', backref='student', lazy=True)
    group = db.Column(db.String(60), nullable=False)


class Student_mark(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    subject = db.Column(db.String(255), nullable=False)
    mark = db.Column(db.Integer, nullable=False)
    student_id = db.Column(db.Integer, db.ForeignKey('student.id'))