Esempio n. 1
0
class Brand(db.Model):
    __tablename__ = "brands"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(128), nullable=False)
    description = db.Column(db.String(256), nullable=False)
    cnpj = db.Column(db.String(20), nullable=False)
    products = db.relationship("Product", backref="brands", lazy=True)

    def __init__(self, name, description, cnpj):
        self.name = name
        self.description = description
        self.cnpj = cnpj

    def __repr__(self):
        return "Brand({})".format(self.id)
Esempio n. 2
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)
Esempio n. 3
0
class Session(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    key = db.Column(db.String(32), nullable=False, unique=True)
    created_at = db.Column(db.DateTime, default=db.func.now())

    games = db.relationship('Game', back_populates='session')

    @staticmethod
    def create_session():
        new_session = Session(key=uuid4().hex)
        db.session.add(new_session)
        db.session.commit()
        
        return new_session
Esempio n. 4
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)
Esempio n. 5
0
class Client(db.Model):
    __tablename__ = "clients"

    id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.String(128), nullable=False)
    full_name = db.Column(db.String(256), nullable=False)
    cnpj = db.Column(db.String(32), nullable=False)
    address = db.Column(db.String(256), nullable=False)
    email = db.Column(db.String(128), nullable=False)
    phone = db.Column(db.String(32), nullable=False)
    created_at = db.Column(db.Date, nullable=False)
    orders = db.relationship("Order", backref="clients", lazy=True)

    def __init__(self, first_name, full_name, cnpj, address, email, phone):
        self.first_name = first_name
        self.full_name = full_name
        self.cnpj = cnpj
        self.address = address
        self.email = email
        self.phone = phone
        self.created_at = date.today()

    def __repr__(self):
        return "Client({})".format(self.first_name)