2019-09-10 01:06:11 +02:00
|
|
|
"Script for everything Product related in the database"
|
2019-08-28 03:46:04 +02:00
|
|
|
from models import db
|
|
|
|
|
2019-09-08 00:41:50 +02:00
|
|
|
from .location import Location
|
|
|
|
|
2019-08-28 03:46:04 +02:00
|
|
|
|
|
|
|
class Product(db.Model):
|
2019-09-10 01:06:11 +02:00
|
|
|
"Class used for configuring the Product model in the database"
|
2019-08-28 03:46:04 +02:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2019-09-05 03:33:29 +02:00
|
|
|
location_id = db.Column(db.Integer, db.ForeignKey("location.id"))
|
2019-08-28 03:46:04 +02:00
|
|
|
name = db.Column(db.String(120), nullable=False)
|
|
|
|
price = db.Column(db.Integer, nullable=False)
|
2019-09-10 01:06:11 +02:00
|
|
|
orderItems = db.relationship("OrderItem",
|
|
|
|
backref="product", lazy="dynamic")
|
2019-08-28 03:46:04 +02:00
|
|
|
|
2019-09-08 00:41:50 +02:00
|
|
|
def configure(self, location: Location, name: str, price: int) -> None:
|
2019-09-10 01:06:11 +02:00
|
|
|
"Configure the Product"
|
|
|
|
# pylint: disable=W0201
|
2019-08-28 03:46:04 +02:00
|
|
|
self.location = location
|
|
|
|
self.name = name
|
|
|
|
self.price = price
|
|
|
|
|
2019-09-08 00:41:50 +02:00
|
|
|
def __repr__(self) -> str:
|
2019-09-10 01:06:11 +02:00
|
|
|
return "%s (€%d)from %s" % (self.name, self.price / 100,
|
|
|
|
self.location or "None",)
|