barker/barker/barker/models/section_printer.py

54 lines
1.8 KiB
Python

import uuid
from typing import TYPE_CHECKING
from sqlalchemy import ForeignKey, Integer, UniqueConstraint, text
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import Mapped, mapped_column, relationship
from ..db.base_class import reg
if TYPE_CHECKING:
from .printer import Printer
from .sale_category import SaleCategory
from .section import Section
@reg.mapped_as_dataclass(unsafe_hash=True)
class SectionPrinter:
__tablename__ = "section_printers"
__table_args__ = (UniqueConstraint("sale_category_id", "section_id"),)
id: Mapped[uuid.UUID] = mapped_column(
"id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4
)
sale_category_id: Mapped[uuid.UUID] = mapped_column(
"sale_category_id", UUID(as_uuid=True), ForeignKey("sale_categories.id"), nullable=True
)
section_id: Mapped[uuid.UUID] = mapped_column(
"section_id", UUID(as_uuid=True), ForeignKey("sections.id"), nullable=False
)
printer_id: Mapped[uuid.UUID] = mapped_column(
"printer_id", UUID(as_uuid=True), ForeignKey("printers.id"), nullable=False
)
copies: Mapped[int] = mapped_column("copies", Integer, nullable=False)
sale_category: Mapped["SaleCategory"] = relationship("SaleCategory", backref="section_printers")
section: Mapped["Section"] = relationship("Section", backref="section_printers")
printer: Mapped["Printer"] = relationship("Printer", backref="section_printers")
def __init__(
self,
sale_category_id=None,
section_id=None,
printer_id=None,
copies=None,
id_=None,
):
self.id = id_
self.sale_category_id = sale_category_id
self.section_id = section_id
self.printer_id = printer_id
self.copies = copies