Skip to content
Snippets Groups Projects
Commit 9ddee740 authored by robban64's avatar robban64
Browse files

add: filename to schema and changed image_id to media_id

parent c70fe559
No related branches found
No related tags found
1 merge request!96Resolve "Inherit from another table"
This commit is part of merge request !96. Comments created here will be created in the context of that merge request.
......@@ -103,7 +103,7 @@ component_create_parser = component_parser.copy()
# component_create_parser.replace_argument("data", type=dict, required=True, location="json")
component_create_parser.add_argument("type_id", type=int, required=True, location="json")
component_create_parser.add_argument("text", type=str, required=False, location="json")
component_create_parser.add_argument("image_id", type=str, required=False, location="json")
component_create_parser.add_argument("media_id", type=str, required=False, location="json")
login_code_parser = reqparse.RequestParser()
login_code_parser.add_argument("code", type=str, location="json")
......@@ -165,4 +165,5 @@ class ComponentSchema(BaseSchema):
type_id = ma.auto_field()
text = fields.fields.String()
image_id = fields.fields.Integer()
media_id = fields.fields.Integer()
filename = ma.Function(lambda x: x.media.filename if hasattr(x, "media_id") else "")
......@@ -84,7 +84,7 @@ def component(type_id, slide_id, x=0, y=0, w=0, h=0, **data):
item.text = data.get("text")
elif type_id == 2:
item = db_add(ImageComponent(slide_id, type_id, x, y, w, h))
item.image_id = data.get("image_id")
item.media_id = data.get("media_id")
else:
abort(codes.BAD_REQUEST, f"Invalid type_id{type_id}")
......
......@@ -41,7 +41,7 @@ def _component(item_component, item_slide_new):
if item_component.type_id == 1:
data["text"] = item_component.text
elif item_component.type_id == 2:
data["image_id"] = item_component.image_id
data["media_id"] = item_component.media_id
add.component(
item_component.type_id,
item_slide_new.id,
......
......@@ -217,7 +217,8 @@ class TextComponent(Component):
class ImageComponent(Component):
image_id = db.Column(db.Integer, db.ForeignKey("media.id"), nullable=True)
media_id = db.Column(db.Integer, db.ForeignKey("media.id"), nullable=True)
media = db.relationship("Media", uselist=False)
# __tablename__ = None
__mapper_args__ = {"polymorphic_identity": ID_IMAGE_COMPONENT}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment