1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
Kfet-depreciated/app/models.py

125 lines
3.9 KiB
Python
Raw Normal View History

2020-02-01 16:43:22 +01:00
import datetime
from flask_login import UserMixin
2020-01-26 21:24:49 +01:00
from werkzeug.security import generate_password_hash, check_password_hash
from app import db
from app import login
class User(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
2020-02-01 16:43:22 +01:00
2020-01-26 21:24:49 +01:00
username = db.Column(db.String, index=True, unique=True)
password_hash = db.Column(db.String)
2020-02-01 16:43:22 +01:00
firstname = db.Column(db.String, nullable=False)
lastname = db.Column(db.String, nullable=False)
command = db.relationship("Command", backref="client", lazy="dynamic", foreign_keys="Command.client_id")
pc_command = db.relationship("Command", backref="pc", lazy="dynamic", foreign_keys="Command.pc_id")
sandwitch_command = db.relationship("Command", backref="sandwitch", lazy="dynamic", foreign_keys="Command.sandwitch_id")
2020-01-26 21:24:49 +01:00
def set_password(self, password):
self.password_hash = generate_password_hash(password)
def check_password(self, password):
return check_password_hash(self.password_hash, password)
def __repr__(self):
return f"<User {self.username}>"
@login.user_loader
def load_user(id):
return User.query.get(int(id))
2020-02-01 16:43:22 +01:00
class Command(db.Model):
id = db.Column(db.Integer, primary_key=True)
number = db.Column(db.Integer, nullable=False)
pc_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
sandwitch_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
client_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
date = db.Column(db.Date, default=datetime.datetime.now().date)
take = db.Column(db.Time, default=datetime.datetime.now().time)
done = db.Column(db.Time)
give = db.Column(db.Time)
error = db.Column(db.Boolean, default=False)
plate_id = db.Column(db.String, db.ForeignKey("plate.id"))
content = db.relationship("Ingredient", secondary="get")
sauce = db.relationship("Sauce", secondary="cover")
drink_id = db.Column(db.String, db.ForeignKey("drink.id"))
dessert_id = db.Column(db.String, db.ForeignKey("dessert.id"))
def __repr__(self):
return f"<Command N°{self.number} {self.date}>"
class Plate(db.Model):
id = db.Column(db.String, primary_key=True)
name = db.Column(db.String, nullable=False)
command = db.relationship("Command", backref="plate", lazy="dynamic")
def __repr__(self):
return f"<Plate {self.id}>"
class Ingredient(db.Model):
id = db.Column(db.String, primary_key=True)
name = db.Column(db.String, nullable=False)
command = db.relationship("Command", secondary="get")
def __repr__(self):
return f"<Ingredient {self.id}>"
class Get(db.Model):
command_id = db.Column(db.Integer, db.ForeignKey("command.id"), primary_key=True)
ingredient_id = db.Column(db.String, db.ForeignKey("ingredient.id"), primary_key=True)
command = db.relationship("Command", backref="get")
content = db.relationship("Ingredient", backref="get")
class Sauce(db.Model):
id = db.Column(db.String, primary_key=True)
name = db.Column(db.String, nullable=False)
command = db.relationship("Command", secondary="cover")
def __repr__(self):
return f"<Sauce {self.id}>"
class Cover(db.Model):
command_id = db.Column(db.Integer, db.ForeignKey("command.id"), primary_key=True)
sauce_id = db.Column(db.String, db.ForeignKey("sauce.id"), primary_key=True)
command = db.relationship("Command", backref="cover")
sauce = db.relationship("Sauce", backref="cover")
class Drink(db.Model):
id = db.Column(db.String, primary_key=True)
name = db.Column(db.String, nullable=False)
command = db.relationship("Command", backref="drink", lazy="dynamic")
def __repr__(self):
return f"<Drink {self.id}>"
class Dessert(db.Model):
id = db.Column(db.String, primary_key=True)
name = db.Column(db.String, nullable=False)
command = db.relationship("Command", backref="dessert", lazy="dynamic")
def __repr__(self):
return f"<Dessert {self.id}>"