Esempio n. 1
0
class Recipe(db.Model):
    __tablename__ = 'recipes'
    __table_args__ = (db.UniqueConstraint('name', 'version', name='uix_1'), )
    id = db.Column(db.Integer, primary_key=True)
    userid = db.Column(db.Integer, db.ForeignKey('users.id'))
    name = db.Column("name", db.String)
    public = db.Column("public", db.Boolean)
    version = db.Column("version", db.Integer)
    batchvolume = db.Column("batchvolume", db.Integer)
    batchnic = db.Column("batchnic", db.Integer)
    batchratio = db.Column("batchratio", db.Integer)
    basenic = db.Column("basenic", db.Integer)
    baseratio = db.Column("baseratio", db.Integer)
    flavours = db.relationship("Flavour", cascade="all, delete-orphan")

    def __eq__(self, other):
        return (self.name == other.name
                and int(self.public) == int(other.public)
                and int(self.batchvolume) == int(other.batchvolume)
                and int(self.batchnic) == int(other.batchnic)
                and int(self.batchratio) == int(other.batchratio)
                and int(self.basenic) == int(other.basenic)
                and int(self.baseratio) == int(other.baseratio)
                and self.flavours == other.flavours)

    def as_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}
Esempio n. 2
0
class Time(db.Model):
    __tablename__ = "times"

    id = db.Column(db.Integer, primary_key=True)
    time = db.Column(db.String, nullable=False)
    is_free = db.Column(db.Boolean, nullable=False)

    day_id = db.Column(db.Integer, db.ForeignKey("days.id"))
    day = db.relationship("Day")
Esempio n. 3
0
class Booking(db.Model):
    __tablename__ = "bookings"

    id = db.Column(db.Integer, primary_key=True)
    day = db.Column(db.String, nullable=False)
    time = db.Column(db.String, nullable=False)
    name = db.Column(db.String, nullable=False)
    phone = db.Column(db.String, nullable=False)

    teacher_id = db.Column(db.Integer, db.ForeignKey("teachers.id"))
    teacher = db.relationship("Teacher")
Esempio n. 4
0
class Flavour(db.Model):
    __tablename__ = 'flavours'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column("name", db.String)
    percentage = db.Column("percentage", db.Integer)
    recipeid = db.Column(db.Integer, db.ForeignKey('recipes.id'))

    def __eq__(self, other):
        return (self.name == other.name
                and int(self.percentage) == int(other.percentage))

    def __ne__(self, other):
        return (self.name != other.name or self.percentage != other.percentage)

    def __hash__(self):
        return hash(self.name + str(self.percentage))

    def as_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}
Esempio n. 5
0
from app_setup import db

goals_relations_association = db.Table(
    'goals_relations',
    db.Column('teacher_id', db.Integer(), db.ForeignKey('teachers.id')),
    db.Column('goal_id', db.Integer(), db.ForeignKey('goals.id')))

days_relations_association = db.Table(
    'days_relations',
    db.Column('teacher_id', db.Integer(), db.ForeignKey('teachers.id')),
    db.Column('day_id', db.Integer(), db.ForeignKey('days.id')))


class Teacher(db.Model):
    __tablename__ = "teachers"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False)
    about = db.Column(db.String, nullable=False)
    rating = db.Column(db.Float, nullable=False)
    picture = db.Column(db.String, nullable=False)
    price = db.Column(db.Float, nullable=False)

    bookings = db.relationship("Booking")

    goals = db.relationship("Goal",
                            secondary=goals_relations_association,
                            back_populates='teachers')

    days = db.relationship("Day",
                           secondary=days_relations_association,