This commit is contained in:
3
mealapi/model/__init__.py
Normal file
3
mealapi/model/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
from .db import db
|
||||
from .meal import Meal
|
||||
from .ingredient import Ingredient
|
4
mealapi/model/db.py
Normal file
4
mealapi/model/db.py
Normal file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
db = SQLAlchemy()
|
11
mealapi/model/ingredient.py
Normal file
11
mealapi/model/ingredient.py
Normal file
@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env python3
|
||||
from .db import db
|
||||
from .mealingredient import MealIngredient
|
||||
|
||||
|
||||
class Ingredient(db.Model):
|
||||
__tablename__ = 'Ingredient'
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String, nullable=False, unique=True)
|
||||
value = db.Column(db.String, nullable=False)
|
||||
items = db.relationship('Meal', secondary=MealIngredient, back_populates='Ingredient')
|
16
mealapi/model/meal.py
Normal file
16
mealapi/model/meal.py
Normal file
@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env python3
|
||||
from .db import db
|
||||
from .mealingredient import MealIngredient
|
||||
|
||||
|
||||
class Meal(db.Model):
|
||||
__tablename__ = 'Meal'
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(255), nullable=False)
|
||||
description = db.Column(db.Text, nullable=False)
|
||||
kcal = db.Column(db.Integer, nullable=True)
|
||||
price = db.Column(db.Integer, nullable=True)
|
||||
spicy = db.Column(db.Boolean, nullable=False, default=False)
|
||||
vegan = db.Column(db.Boolean, nullable=False, default=False)
|
||||
glutenfree = db.Column(db.Boolean, nullable=False, default=False)
|
||||
ingredients = db.relationship('Ingredient', secondary=MealIngredient, back_populates='Meal')
|
9
mealapi/model/mealingredient.py
Normal file
9
mealapi/model/mealingredient.py
Normal file
@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
from .db import db
|
||||
|
||||
|
||||
class MealIngredient(db.Model):
|
||||
__tablename__ = 'MealIngredient'
|
||||
id = db.Column(db.Integer, primary_key=True, index=True)
|
||||
itemId = db.Column(db.Integer, db.ForeignKey('Meal.id'))
|
||||
detailId = db.Column(db.Integer, db.ForeignKey('Ingredient.id'))
|
Reference in New Issue
Block a user