43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
from sqlalchemy import ForeignKey, Table, Column
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from models.base import BaseModel
|
|
from models.mixins import IdMixin, SoftDeleteMixin
|
|
|
|
barcode_template_attribute_link = Table(
|
|
"barcode_template_attribute_links",
|
|
BaseModel.metadata,
|
|
Column("barcode_template_id", ForeignKey("barcode_templates.id")),
|
|
Column("attribute_id", ForeignKey("barcode_template_attributes.id")),
|
|
)
|
|
|
|
|
|
class BarcodeTemplateAttribute(BaseModel, IdMixin):
|
|
__tablename__ = "barcode_template_attributes"
|
|
|
|
key: Mapped[str] = mapped_column(index=True, comment="Ключ атрибута")
|
|
name: Mapped[str] = mapped_column(index=True, comment="Метка атрибута")
|
|
|
|
|
|
class BarcodeTemplateSize(BaseModel, IdMixin):
|
|
__tablename__ = "barcode_template_sizes"
|
|
|
|
name: Mapped[str] = mapped_column(index=True, comment="Название размера")
|
|
width: Mapped[int] = mapped_column(comment="Ширина в мм")
|
|
height: Mapped[int] = mapped_column(comment="Высота в мм")
|
|
|
|
|
|
class BarcodeTemplate(BaseModel, IdMixin, SoftDeleteMixin):
|
|
__tablename__ = "barcode_templates"
|
|
|
|
name: Mapped[str] = mapped_column(index=True, comment="Название шаблона")
|
|
attributes: Mapped[list["BarcodeTemplateAttribute"]] = relationship(
|
|
secondary=barcode_template_attribute_link,
|
|
lazy="selectin",
|
|
)
|
|
|
|
is_default: Mapped[bool] = mapped_column(default=False, comment="По умолчанию")
|
|
|
|
size_id: Mapped[int] = mapped_column(ForeignKey("barcode_template_sizes.id"))
|
|
size: Mapped["BarcodeTemplateSize"] = relationship(lazy="joined")
|