29 lines
1.2 KiB
Python
29 lines
1.2 KiB
Python
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')
|
|
|
|
|
|
class Product(BaseModel):
|
|
__tablename__ = 'products'
|
|
id = Column(Integer, autoincrement=True, primary_key=True, index=True)
|
|
name = Column(String, nullable=False, index=True)
|
|
article = Column(String, nullable=False, index=True)
|
|
|
|
client_id = Column(Integer, ForeignKey('clients.id'), nullable=False, comment='ID сделки')
|
|
client = relationship('Client', back_populates='products')
|
|
barcodes = relationship('ProductBarcode', back_populates='product', cascade="all, delete-orphan")
|
|
my_column = Column(Integer, sequence)
|
|
|
|
|
|
class ProductBarcode(BaseModel):
|
|
__tablename__ = 'product_barcodes'
|
|
product_id = Column(Integer, ForeignKey('products.id'), nullable=False, comment='ID товара', primary_key=True)
|
|
product = relationship('Product', back_populates='barcodes')
|
|
|
|
barcode = Column(String, nullable=False, index=True, comment='ШК товара', primary_key=True)
|