class User(db.Model, UserMixin): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) admin = db.Column(db.Boolean, nullable=False, default=False) pantry = db.relationship('Pantry', backref="originalUser", lazy=True) savedRecipes = db.relationship('Recipe', backref="originalUser", lazy=True) allergens = db.relationship('Allergen', backref="originalUser", lazy=True) password = db.Column(db.String(60), nullable=False)
class Pantry(db.Model): pantryID = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), nullable=False) pantryIngredients = db.relationship('PantryIngredient', backref='originalPantry', lazy=True) linkedUserID = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def addIngredient(self, form): ingName = form.name.data quantity = form.quantity.data expiryDate = form.expiryDate.data ingredient = PantryIngredient(ingredientName=ingName, quantity=quantity, expiryDate=expiryDate, linkedPantryID=self.pantryID) db.session.add(ingredient) db.session.commit()
class Recipe(db.Model): recipeID = db.Column(db.Integer, primary_key=True) recipeName = db.Column(db.String(40), nullable=False) date = db.Column(db.DateTime()) url = db.Column(db.String(100), unique=True, nullable=False) bbc = db.Column(db.Boolean, default=False) tesco = db.Column(db.Boolean, default=False) sain = db.Column(db.Boolean, default=False) userID = db.Column(db.Integer, db.ForeignKey('user.id'))
class Allergen(db.Model): allergenID = db.Column(db.Integer, primary_key=True) dairyFree = db.Column(db.Boolean, default=False) glutenFree = db.Column(db.Boolean, default=False) vegetarian = db.Column(db.Boolean, default=False) nutFree = db.Column(db.Boolean, default=False) vegan = db.Column(db.Boolean, default=False) linkedUserID = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
class PantryIngredient(db.Model): pingID = db.Column(db.Integer, primary_key=True) ingredientName = db.Column(db.String(50), nullable=False) quantity = db.Column(db.String(20), nullable=False) expiryDate = db.Column(db.DateTime, nullable=False) linkedPantryID = db.Column(db.Integer, db.ForeignKey('pantry.pantryID'), nullable=False)