51 lines
2.4 KiB
Python
51 lines
2.4 KiB
Python
from sqlalchemy import Integer, Column, String, Boolean, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from models import BaseModel, barcode_template_attribute_link
|
|
|
|
|
|
class BarcodeTemplateAttribute(BaseModel):
|
|
__tablename__ = 'barcode_template_attributes'
|
|
id = Column(Integer, autoincrement=True, primary_key=True, index=True)
|
|
key = Column(String, nullable=False, index=True, comment='Ключ атрибута')
|
|
name = Column(String, nullable=False, index=True, comment='Метка атрибута')
|
|
|
|
|
|
class BarcodeTemplateAdditionalField(BaseModel):
|
|
__tablename__ = 'barcode_template_additional_fields'
|
|
name = Column(String, nullable=False, primary_key=True, comment='Название поля')
|
|
value = Column(String, nullable=False)
|
|
|
|
barcode_template_id = Column(Integer, ForeignKey('barcode_templates.id'), nullable=False, primary_key=True)
|
|
barcode_template = relationship('BarcodeTemplate')
|
|
|
|
|
|
class BarcodeTemplateSize(BaseModel):
|
|
__tablename__ = 'barcode_template_sizes'
|
|
id = Column(Integer, autoincrement=True, primary_key=True, index=True)
|
|
|
|
name = Column(String, nullable=False, index=True, comment='Название размера')
|
|
key = Column(String, nullable=False, index=True, comment='Ключ размера')
|
|
|
|
width = Column(Integer, nullable=False, comment='Ширина в мм')
|
|
height = Column(Integer, nullable=False, comment='Высота в мм')
|
|
|
|
|
|
class BarcodeTemplate(BaseModel):
|
|
__tablename__ = 'barcode_templates'
|
|
id = Column(Integer, autoincrement=True, primary_key=True, index=True)
|
|
name = Column(String, nullable=False, index=True, comment='Название шаблона')
|
|
attributes = relationship('BarcodeTemplateAttribute',
|
|
secondary=barcode_template_attribute_link,
|
|
lazy='selectin'
|
|
)
|
|
additional_attributes = relationship('BarcodeTemplateAdditionalField',
|
|
lazy='selectin',
|
|
back_populates='barcode_template',
|
|
cascade="all, delete")
|
|
|
|
is_default = Column(Boolean, nullable=False, default=False, comment='По умолчанию')
|
|
|
|
size_id = Column(Integer, ForeignKey('barcode_template_sizes.id'), nullable=False)
|
|
size = relationship('BarcodeTemplateSize', lazy='joined')
|