Exemple #1
0
class Order(db.Model):
    __tablename__ = "orders"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    total_price = db.Column(db.Float, nullable=False)
    sale_date = db.Column(db.Date, nullable=False)
    number_of_items = db.Column(db.Integer, nullable=False)
    status = db.Column(db.String(64), nullable=False)
    delivery_date = db.Column(db.Date, nullable=False)
    client_id = db.Column(db.Integer,
                          db.ForeignKey("clients.id"),
                          nullable=False)
    order_items = db.relationship("Order_Item", backref="orders", lazy=True)

    def __init__(self, total_price, sale_date, number_of_items, status,
                 delivery_date, client_id):
        self.total_price = total_price
        self.sale_date = sale_date
        self.number_of_items = number_of_items
        self.status = status
        self.delivery_date = delivery_date
        self.client_id = client_id

    def __repr__(self):
        return "Order(id: {})".format(self.id)
Exemple #2
0
class Move(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    game_id = db.Column(db.Integer, db.ForeignKey('game.id'))
    created_at = db.Column(db.DateTime, default=db.func.now())
    player = db.Column(db.Enum(Player), nullable=False)
    move_x = db.Column(db.Integer)
    move_y = db.Column(db.Integer)
    score = db.Column(db.Integer)

    game = db.relationship('Game', back_populates='moves')
Exemple #3
0
class Game(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    session_id = db.Column(db.Integer, db.ForeignKey('session.id'))
    board1 = db.Column(db.Text)
    board2 = db.Column(db.Text)
    winner = db.Column(db.Enum(Player), nullable=True)
    move = db.Column(db.Enum(Player), nullable=False)
    created_at = db.Column(db.DateTime, default=db.func.now())
    finished_at = db.Column(db.DateTime)

    session = db.relationship('Session', back_populates='games')
    moves = db.relationship('Move', back_populates='game')
Exemple #4
0
class Order_Item(db.Model):
    __tablename__ = "order_items"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    quantity = db.Column(db.Integer, nullable=False)
    order_price = db.Column(db.Float, nullable=False)
    product_id = db.Column(db.Integer,
                           db.ForeignKey("products.id"),
                           nullable=False)
    order_id = db.Column(db.Integer,
                         db.ForeignKey("orders.id"),
                         nullable=False)

    def __init__(self, order_id, product_id, quantity, order_price):
        self.order_id = order_id
        self.product_id = product_id
        self.quantity = quantity
        self.order_price = order_price

    def __repr__(self):
        return "Order_Item(id: {})".format(self.id)
Exemple #5
0
class Lot(db.Model):
    __tablename__ = "lots"

    id = db.Column(db.Integer, primary_key=True)
    product_id = db.Column(db.Integer,
                           db.ForeignKey("products.id"),
                           nullable=False)
    purchase_price = db.Column(db.Float, nullable=False)
    validity_date = db.Column(db.Date, nullable=False)
    lot_quantity = db.Column(db.Integer, nullable=False)

    def __init__(self, product_id, purchase_price, validity_date,
                 lot_quantity):
        self.product_id = product_id
        self.purchase_price = purchase_price
        self.validity_date = validity_date
        self.lot_quantity = lot_quantity

    def __repr__(self):
        return "Lot({})".format(self.id)
Exemple #6
0
class Product(db.Model):
    __tablename__ = "products"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(128), nullable=False)
    description = db.Column(db.String(256), nullable=False)
    sale_price = db.Column(db.Float, nullable=False)
    total_quantity = db.Column(db.Integer, nullable=False)
    actived = db.Column(db.SmallInteger, nullable=False)
    min_quantity = db.Column(db.Integer)
    brand_id = db.Column(db.Integer,
                         db.ForeignKey("brands.id"),
                         nullable=False)
    orders = db.relationship("Order_Item", backref="products", lazy=True)
    lots = db.relationship("Lot", backref="products", lazy=True)

    def __init__(
        self,
        name,
        description,
        sale_price,
        total_quantity,
        actived,
        brand_id,
        min_quantity,
    ):
        self.name = name
        self.description = description
        self.sale_price = sale_price
        self.total_quantity = total_quantity
        self.actived = actived
        self.brand_id = brand_id
        self.min_quantity = min_quantity

    def __repr__(self):
        return "Product({})".format(self.name)
Exemple #7
0
class Question(db.Model):
    __tablename__ = 'questions'

    id = db.Column(db.Integer, primary_key=True)
    question = db.Column(db.String, nullable=False)
    answer = db.Column(db.String, nullable=False)
    category_id = db.Column(db.Integer,
                            db.ForeignKey('categories.id'),
                            nullable=False)
    difficulty = db.Column(db.Integer, nullable=False)

    def __init__(self, question, answer, category_id, difficulty):
        self.question = question
        self.answer = answer
        self.category_id = category_id
        self.difficulty = difficulty

    def insert(self):
        db.session.add(self)
        db.session.commit()

    def update(self):
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()

    def format(self):
        return {
            'id': self.id,
            'question': self.question,
            'answer': self.answer,
            'category_id': self.category_id,
            'difficulty': self.difficulty
        }
Exemple #8
0
class ToDo(db.Model):
    __tablename__ = 'todo'
    id = db.Column(db.Integer, nullable=False, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    title = db.Column(db.Text, nullable=False)
    description = db.Column(db.Text, nullable=False)