feat: a few shipping products in box
This commit is contained in:
		@@ -5,7 +5,7 @@ from sqlalchemy.orm import Mapped, mapped_column, relationship
 | 
			
		||||
from models import BaseModel
 | 
			
		||||
 | 
			
		||||
if TYPE_CHECKING:
 | 
			
		||||
    from models import Card, Product, Client
 | 
			
		||||
    from models import Card, Product
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Pallet(BaseModel):
 | 
			
		||||
@@ -30,6 +30,24 @@ class Pallet(BaseModel):
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Box(BaseModel):
 | 
			
		||||
    __tablename__ = 'boxes'
 | 
			
		||||
    id: Mapped[int] = mapped_column(primary_key=True)
 | 
			
		||||
 | 
			
		||||
    shipping_products: Mapped[list['ShippingProduct']] = relationship(
 | 
			
		||||
        back_populates='box',
 | 
			
		||||
        uselist=True,
 | 
			
		||||
        lazy='joined',
 | 
			
		||||
        cascade='all, delete-orphan',
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    pallet_id: Mapped[Optional[int]] = mapped_column(ForeignKey('pallets.id'))
 | 
			
		||||
    pallet: Mapped[Pallet] = relationship(back_populates='boxes')
 | 
			
		||||
 | 
			
		||||
    card_id: Mapped[Optional[int]] = mapped_column(ForeignKey('cards.id'))
 | 
			
		||||
    card: Mapped['Card'] = relationship(back_populates='boxes')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ShippingProduct(BaseModel):
 | 
			
		||||
    __tablename__ = 'shipping_products'
 | 
			
		||||
    id: Mapped[int] = mapped_column(primary_key=True)
 | 
			
		||||
@@ -38,21 +56,8 @@ class ShippingProduct(BaseModel):
 | 
			
		||||
    product_id: Mapped[int] = mapped_column(ForeignKey('products.id'))
 | 
			
		||||
    product: Mapped['Product'] = relationship(lazy='joined')
 | 
			
		||||
 | 
			
		||||
    pallet_id: Mapped[int] = mapped_column(ForeignKey('pallets.id'))
 | 
			
		||||
    pallet: Mapped['Pallet'] = relationship(lazy='joined')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Box(BaseModel):
 | 
			
		||||
    __tablename__ = 'boxes'
 | 
			
		||||
    id: Mapped[int] = mapped_column(primary_key=True)
 | 
			
		||||
 | 
			
		||||
    quantity: Mapped[int] = mapped_column(default=0)
 | 
			
		||||
 | 
			
		||||
    product_id: Mapped[Optional[int]] = mapped_column(ForeignKey('products.id'), nullable=True)
 | 
			
		||||
    product: Mapped['Product'] = relationship(lazy='joined')
 | 
			
		||||
 | 
			
		||||
    pallet_id: Mapped[Optional[int]] = mapped_column(ForeignKey('pallets.id'))
 | 
			
		||||
    pallet: Mapped[Pallet] = relationship(back_populates='boxes')
 | 
			
		||||
    pallet: Mapped[Optional['Pallet']] = relationship(lazy='joined')
 | 
			
		||||
 | 
			
		||||
    card_id: Mapped[Optional[int]] = mapped_column(ForeignKey('cards.id'))
 | 
			
		||||
    card: Mapped['Card'] = relationship(back_populates='boxes')
 | 
			
		||||
    box_id: Mapped[Optional[int]] = mapped_column(ForeignKey('boxes.id'))
 | 
			
		||||
    box: Mapped[Optional['Box']] = relationship(lazy='joined')
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user