Skip to content

Commit

Permalink
feat: schemas use marshmallow-sqlalchemy
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdur-rahmaanJ committed Sep 26, 2024
1 parent 7d4b5dc commit 98ffd9c
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/shopcube/modules/box__ecommerce/product/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from werkzeug.utils import secure_filename

from init import db
from init import ma
from init import productphotos

from modules.box__ecommerce.category.models import SubCategory
Expand All @@ -28,6 +27,9 @@
from modules.box__ecommerce.product.models import Size
from modules.resource.models import Resource

from marshmallow_sqlalchemy import SQLAlchemySchema, auto_field


dirpath = os.path.dirname(os.path.abspath(__file__))
module_info = {}

Expand All @@ -42,23 +44,23 @@
url_prefix=module_info["url_prefix"],
)


class Productchema(ma.Schema):
class ProductSchema(SQLAlchemySchema):
class Meta:
# Fields to expose
fields = (
"barcode",
"name",
"description",
"price",
"selling_price",
"in_stock",
"discontinued",
)
model = Product
load_instance = True # Optional: deserialize to model instances

barcode = auto_field()
name = auto_field()
description = auto_field()
price = auto_field()
selling_price = auto_field()
in_stock = auto_field()
discontinued = auto_field()



product_schema = Productchema()
product_schema = Productchema(many=True)
product_schema = ProductSchema()
product_schema = ProductSchema(many=True)

module_blueprint = globals()["{}_blueprint".format(module_info["module_name"])]

Expand Down

0 comments on commit 98ffd9c

Please sign in to comment.