diff --git a/reciperadar/models/recipes/appliance.py b/reciperadar/models/recipes/appliance.py index ef3f14b..ded4730 100644 --- a/reciperadar/models/recipes/appliance.py +++ b/reciperadar/models/recipes/appliance.py @@ -1,20 +1,15 @@ -from sqlalchemy import ( - Column, - ForeignKey, - String, -) - +from reciperadar import db from reciperadar.models.base import Storable class DirectionAppliance(Storable): __tablename__ = 'direction_appliances' - fk = ForeignKey('recipe_directions.id', ondelete='cascade') - direction_id = Column(String, fk, index=True) + fk = db.ForeignKey('recipe_directions.id', ondelete='cascade') + direction_id = db.Column(db.String, fk, index=True) - id = Column(String, primary_key=True) - appliance = Column(String) + id = db.Column(db.String, primary_key=True) + appliance = db.Column(db.String) @staticmethod def from_doc(doc): diff --git a/reciperadar/models/recipes/direction.py b/reciperadar/models/recipes/direction.py index 0f6f61a..a38f19e 100644 --- a/reciperadar/models/recipes/direction.py +++ b/reciperadar/models/recipes/direction.py @@ -1,11 +1,4 @@ -from sqlalchemy import ( - Column, - ForeignKey, - Integer, - String, -) -from sqlalchemy.orm import relationship - +from reciperadar import db from reciperadar.models.base import Storable from reciperadar.models.recipes.appliance import DirectionAppliance from reciperadar.models.recipes.utensil import DirectionUtensil @@ -15,24 +8,24 @@ class RecipeDirection(Storable): __tablename__ = 'recipe_directions' - fk = ForeignKey('recipes.id', ondelete='cascade') - recipe_id = Column(String, fk, index=True) + fk = db.ForeignKey('recipes.id', ondelete='cascade') + recipe_id = db.Column(db.String, fk, index=True) - id = Column(String, primary_key=True) - index = Column(Integer) - description = Column(String) - markup = Column(String) - appliances = relationship( + id = db.Column(db.String, primary_key=True) + index = db.Column(db.Integer) + description = db.Column(db.String) + markup = db.Column(db.String) + appliances = db.relationship( 'DirectionAppliance', backref='recipe_directions', passive_deletes='all' ) - utensils = relationship( + utensils = db.relationship( 'DirectionUtensil', backref='recipe_directions', passive_deletes='all' ) - vessels = relationship( + vessels = db.relationship( 'DirectionVessel', backref='recipe_directions', passive_deletes='all' diff --git a/reciperadar/models/recipes/ingredient.py b/reciperadar/models/recipes/ingredient.py index 1833244..43a47bc 100644 --- a/reciperadar/models/recipes/ingredient.py +++ b/reciperadar/models/recipes/ingredient.py @@ -1,12 +1,4 @@ -from sqlalchemy import ( - Column, - Float, - ForeignKey, - Integer, - String, -) -from sqlalchemy.orm import relationship - +from reciperadar import db from reciperadar.models.base import Searchable, Storable from reciperadar.models.recipes.product import IngredientProduct @@ -14,25 +6,25 @@ class RecipeIngredient(Storable, Searchable): __tablename__ = 'recipe_ingredients' - fk = ForeignKey('recipes.id', ondelete='cascade') - recipe_id = Column(String, fk, index=True) + fk = db.ForeignKey('recipes.id', ondelete='cascade') + recipe_id = db.Column(db.String, fk, index=True) - id = Column(String, primary_key=True) - index = Column(Integer) - description = Column(String) - markup = Column(String) - product = relationship( + id = db.Column(db.String, primary_key=True) + index = db.Column(db.Integer) + description = db.Column(db.String) + markup = db.Column(db.String) + product = db.relationship( 'IngredientProduct', backref='recipe_ingredient', uselist=False, passive_deletes='all' ) - quantity = Column(Float) - quantity_parser = Column(String) - units = Column(String) - units_parser = Column(String) - verb = Column(String) + quantity = db.Column(db.Float) + quantity_parser = db.Column(db.String) + units = db.Column(db.String) + units_parser = db.Column(db.String) + verb = db.Column(db.String) @staticmethod def from_doc(doc): diff --git a/reciperadar/models/recipes/product.py b/reciperadar/models/recipes/product.py index 96ffc32..755111a 100644 --- a/reciperadar/models/recipes/product.py +++ b/reciperadar/models/recipes/product.py @@ -1,29 +1,24 @@ -from sqlalchemy import ( - Boolean, - Column, - ForeignKey, - String, -) from sqlalchemy.dialects import postgresql +from reciperadar import db from reciperadar.models.base import Storable class IngredientProduct(Storable): __tablename__ = 'ingredient_products' - fk = ForeignKey('recipe_ingredients.id', ondelete='cascade') - ingredient_id = Column(String, fk, index=True) - - id = Column(String, primary_key=True) - product_id = Column(String) - product = Column(String) - product_parser = Column(String) - is_plural = Column(Boolean) - singular = Column(String) - plural = Column(String) - category = Column(String) - contents = Column(postgresql.ARRAY(String)) + fk = db.ForeignKey('recipe_ingredients.id', ondelete='cascade') + ingredient_id = db.Column(db.String, fk, index=True) + + id = db.Column(db.String, primary_key=True) + product_id = db.Column(db.String) + product = db.Column(db.String) + product_parser = db.Column(db.String) + is_plural = db.Column(db.Boolean) + singular = db.Column(db.String) + plural = db.Column(db.String) + category = db.Column(db.String) + contents = db.Column(postgresql.ARRAY(db.String)) STATE_AVAILABLE = 'available' STATE_REQUIRED = 'required' diff --git a/reciperadar/models/recipes/recipe.py b/reciperadar/models/recipes/recipe.py index 00bce37..c6b00df 100644 --- a/reciperadar/models/recipes/recipe.py +++ b/reciperadar/models/recipes/recipe.py @@ -1,12 +1,4 @@ -from sqlalchemy import ( - Column, - DateTime, - Float, - Integer, - String, -) -from sqlalchemy.orm import relationship - +from reciperadar import db from reciperadar.models.base import Searchable, Storable from reciperadar.models.recipes.direction import RecipeDirection from reciperadar.models.recipes.ingredient import RecipeIngredient @@ -15,27 +7,27 @@ class Recipe(Storable, Searchable): __tablename__ = 'recipes' - id = Column(String, primary_key=True) - title = Column(String) - src = Column(String) - dst = Column(String) - domain = Column(String) - image_src = Column(String) - time = Column(Integer) - servings = Column(Integer) - rating = Column(Float) - ingredients = relationship( + id = db.Column(db.String, primary_key=True) + title = db.Column(db.String) + src = db.Column(db.String) + dst = db.Column(db.String) + domain = db.Column(db.String) + image_src = db.Column(db.String) + time = db.Column(db.Integer) + servings = db.Column(db.Integer) + rating = db.Column(db.Float) + ingredients = db.relationship( 'RecipeIngredient', backref='recipe', passive_deletes='all' ) - directions = relationship( + directions = db.relationship( 'RecipeDirection', backref='recipe', passive_deletes='all' ) - indexed_at = Column(DateTime) + indexed_at = db.Column(db.DateTime) @property def noun(self): diff --git a/reciperadar/models/recipes/utensil.py b/reciperadar/models/recipes/utensil.py index 2101843..93ae70b 100644 --- a/reciperadar/models/recipes/utensil.py +++ b/reciperadar/models/recipes/utensil.py @@ -1,20 +1,15 @@ -from sqlalchemy import ( - Column, - ForeignKey, - String, -) - +from reciperadar import db from reciperadar.models.base import Storable class DirectionUtensil(Storable): __tablename__ = 'direction_utensils' - fk = ForeignKey('recipe_directions.id', ondelete='cascade') - direction_id = Column(String, fk, index=True) + fk = db.ForeignKey('recipe_directions.id', ondelete='cascade') + direction_id = db.Column(db.String, fk, index=True) - id = Column(String, primary_key=True) - utensil = Column(String) + id = db.Column(db.String, primary_key=True) + utensil = db.Column(db.String) @staticmethod def from_doc(doc): diff --git a/reciperadar/models/recipes/vessel.py b/reciperadar/models/recipes/vessel.py index 77af20d..3ad2bb7 100644 --- a/reciperadar/models/recipes/vessel.py +++ b/reciperadar/models/recipes/vessel.py @@ -1,20 +1,15 @@ -from sqlalchemy import ( - Column, - ForeignKey, - String, -) - +from reciperadar import db from reciperadar.models.base import Storable class DirectionVessel(Storable): __tablename__ = 'direction_vessels' - fk = ForeignKey('recipe_directions.id', ondelete='cascade') - direction_id = Column(String, fk, index=True) + fk = db.ForeignKey('recipe_directions.id', ondelete='cascade') + direction_id = db.Column(db.String, fk, index=True) - id = Column(String, primary_key=True) - vessel = Column(String) + id = db.Column(db.String, primary_key=True) + vessel = db.Column(db.String) @staticmethod def from_doc(doc):