P5-4777 add listprice resources

This commit is contained in:
Martin Carlsson
2020-01-30 13:59:21 +01:00
committed by GitHub
parent 1d214566ec
commit 2f4275e66a
4 changed files with 147 additions and 3 deletions
+65
View File
@@ -1,7 +1,10 @@
# coding=UTF-8
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):
@@ -13,6 +16,36 @@ class Product(db.Model):
designer = db.relationship("Designer", backref="products")
class ProductField(db.Model):
__tablename__ = "product-fields"
id = db.Column("fieldid", db.Integer, primary_key=True)
field = db.Column(db.String())
inserted = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
updated = db.Column(db.DateTime)
class ProductProductFields(db.Model):
__tablename__ = "product-products_fields"
productid = db.Column(
db.Integer, db.ForeignKey("product-products.productid"), nullable=False
)
fieldid = db.Column(
db.Integer, db.ForeignKey("product-fields.fieldid"), nullable=False
)
value = db.Column(db.String())
inserted = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
updated = db.Column(db.DateTime)
product = db.relationship("Product", backref="fields")
field = db.relationship("ProductField")
__table_args__ = (db.PrimaryKeyConstraint(productid, fieldid),)
class Currencies(db.Model):
__tablename__ = "product-currencies"
@@ -51,3 +84,35 @@ class Material(db.Model):
def __repr__(self):
return self.name
class PrintProductQuery(BaseQuery):
def wallpapers(self):
return self.filter(or_(PrintProduct.groupid == 1, PrintProduct.groupid == 3))
def canvases(self):
return self.filter(PrintProduct.groupid == 2)
def posters(self):
return self.filter(PrintProduct.groupid == 7)
def framed_prints(self):
return self.filter(PrintProduct.groupid == 8)
def with_relations(self):
return self.options(joinedload("*"))
class PrintProduct(db.Model):
__tablename__ = "product-printproducts"
query_class = PrintProductQuery
id = db.Column("printid", db.Integer, primary_key=True)
productid = db.Column(
db.Integer, db.ForeignKey("product-products.productid"), nullable=False
)
groupid = db.Column(db.Integer, nullable=False)
product = db.relationship("Product", backref="printproducts")