diff --git a/api/models/product.py b/api/models/product.py index dfa5e26..f79a81a 100644 --- a/api/models/product.py +++ b/api/models/product.py @@ -4,7 +4,6 @@ from datetime import datetime from api.extensions import db from flask_sqlalchemy import BaseQuery from sqlalchemy import or_ -from sqlalchemy.orm import joinedload class Product(db.Model): @@ -99,9 +98,6 @@ class PrintProductQuery(BaseQuery): def framed_prints(self): return self.filter(PrintProduct.groupid == 8) - def with_relations(self): - return self.options(joinedload("*")) - class PrintProduct(db.Model): @@ -115,4 +111,4 @@ class PrintProduct(db.Model): ) groupid = db.Column(db.Integer, nullable=False) - product = db.relationship("Product", backref="printproducts") + product = db.relationship("Product", backref="printproducts", lazy="joined") diff --git a/api/resources/prices.py b/api/resources/prices.py index 54552f0..a211fca 100644 --- a/api/resources/prices.py +++ b/api/resources/prices.py @@ -512,15 +512,13 @@ def inquiry(inquiry_id): @mod.route("/list-prices//wallpaper") def list_prices_wallpaper(territory): - wallpapers = PrintProduct.query.wallpapers().with_relations().all() + wallpapers = PrintProduct.query.wallpapers().all() result = {} material = Material.query.filter(Material.name == "standard-wallpaper").one() market = market_model.from_territory(territory) for wallpaper in wallpapers: - result[wallpaper.id] = wallpaper_price( - width=100, - height=100, + result[wallpaper.id] = m2_price( material=material, market=market, designer=wallpaper.product.designer, @@ -530,7 +528,7 @@ def list_prices_wallpaper(territory): @mod.route("/list-prices//canvas") def list_prices_canvas(territory): - canvases = PrintProduct.query.canvases().with_relations().all() + canvases = PrintProduct.query.canvases().all() market = market_model.from_territory(territory) result = {} @@ -547,7 +545,7 @@ def list_prices_canvas(territory): @mod.route("/list-prices//poster") def list_prices_posters(territory): - posters = PrintProduct.query.posters().with_relations().all() + posters = PrintProduct.query.posters().all() market = market_model.from_territory(territory) result = {} @@ -564,7 +562,7 @@ def list_prices_posters(territory): @mod.route("/list-prices//framed-print") def list_prices_framed_prints(territory): - framed_prints = PrintProduct.query.framed_prints().with_relations().all() + framed_prints = PrintProduct.query.framed_prints().all() market = market_model.from_territory(territory) result = {}