othr
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from sqlalchemy import Integer, Column, String, Boolean
|
||||
from sqlalchemy import Integer, Column, String, Boolean, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from models import BaseModel
|
||||
from models import BaseModel, barcode_template_attribute_link
|
||||
|
||||
|
||||
class BarcodeTemplateAttribute(BaseModel):
|
||||
@@ -11,14 +11,31 @@ class BarcodeTemplateAttribute(BaseModel):
|
||||
name = Column(String, nullable=False, index=True, comment='Метка атрибута')
|
||||
|
||||
|
||||
class BarcodeTemplateAdditionalField(BaseModel):
|
||||
__tablename__ = 'barcode_template_additional_fields'
|
||||
id = Column(Integer, autoincrement=True, primary_key=True, index=True)
|
||||
name = Column(String, nullable=False)
|
||||
value = Column(String, nullable=False)
|
||||
|
||||
barcode_template_id = Column(Integer, ForeignKey('barcode_templates.id'), nullable=False)
|
||||
barcode_template = relationship('BarcodeTemplate', back_populates='additional_fields')
|
||||
|
||||
|
||||
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('BarcodeTemplateAttributeLink',
|
||||
back_populates='barcode_template',
|
||||
cascade="all, delete-orphan",
|
||||
lazy='joined')
|
||||
attributes = relationship('BarcodeTemplateAttribute',
|
||||
secondary=barcode_template_attribute_link,
|
||||
# back_populates='barcode_template',
|
||||
# cascade="all, delete-orphan",
|
||||
lazy='selectin'
|
||||
)
|
||||
additional_fields = relationship('BarcodeTemplateAdditionalField',
|
||||
back_populates='barcode_template',
|
||||
lazy='selectin'
|
||||
)
|
||||
|
||||
is_default = Column(Boolean, nullable=False, default=False, comment='По умолчанию')
|
||||
|
||||
# size
|
||||
|
||||
@@ -14,7 +14,7 @@ class Client(BaseModel):
|
||||
details = relationship('ClientDetails', uselist=False, back_populates='client', cascade='all, delete')
|
||||
|
||||
barcode_template_id = Column(Integer, ForeignKey('barcode_templates.id'), nullable=True)
|
||||
barcode_template = relationship('BarcodeTemplate')
|
||||
barcode_template = relationship('BarcodeTemplate', lazy='selectin')
|
||||
|
||||
|
||||
class ClientDetails(BaseModel):
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
from enum import IntEnum, unique
|
||||
|
||||
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Boolean, Sequence
|
||||
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Boolean
|
||||
from sqlalchemy.orm import relationship, backref
|
||||
|
||||
from models.base import BaseModel, metadata
|
||||
from models.utils import add_sequence_to_model
|
||||
from models.base import BaseModel
|
||||
|
||||
|
||||
@unique
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, Sequence
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from models import BaseModel, metadata
|
||||
|
||||
deal_rank_seq = Sequence('test_ochko', start=1, increment=1, metadata=metadata)
|
||||
|
||||
sequence = Sequence('my_sequence_name')
|
||||
from models import BaseModel
|
||||
|
||||
|
||||
class Product(BaseModel):
|
||||
|
||||
@@ -33,18 +33,26 @@ class DealProduct(BaseModel):
|
||||
quantity = Column(Integer, nullable=False, comment='Кол-во продукта')
|
||||
|
||||
|
||||
class BarcodeTemplateAttributeLink(BaseModel):
|
||||
__tablename__ = 'barcode_template_attributes_links'
|
||||
barcode_template_id = Column(Integer,
|
||||
ForeignKey('barcode_templates.id'),
|
||||
nullable=False,
|
||||
comment='ID Шаблона ШК',
|
||||
primary_key=True)
|
||||
barcode_template = relationship('BarcodeTemplate', back_populates='attributes')
|
||||
|
||||
attribute_id = Column(Integer,
|
||||
ForeignKey('barcode_template_attributes.id'),
|
||||
nullable=False,
|
||||
comment='ID Атрибута',
|
||||
primary_key=True)
|
||||
attribute = relationship('BarcodeTemplateAttribute')
|
||||
# class BarcodeTemplateAttributeLink(BaseModel):
|
||||
# __tablename__ = 'barcode_template_attributes_links'
|
||||
# barcode_template_id = Column(Integer,
|
||||
# ForeignKey('barcode_templates.id'),
|
||||
# nullable=False,
|
||||
# comment='ID Шаблона ШК',
|
||||
# primary_key=True)
|
||||
# barcode_template = relationship('BarcodeTemplate',
|
||||
# # back_populates='attributes'
|
||||
# )
|
||||
#
|
||||
# attribute_id = Column(Integer,
|
||||
# ForeignKey('barcode_template_attributes.id'),
|
||||
# nullable=False,
|
||||
# comment='ID Атрибута',
|
||||
# primary_key=True)
|
||||
# attribute = relationship('BarcodeTemplateAttribute')
|
||||
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'))
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user