73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
|
|
from sqlalchemy import String, Text, ForeignKey, UniqueConstraint
|
||
|
|
from sqlalchemy.orm import Mapped, mapped_column, declared_attr
|
||
|
|
|
||
|
|
from .base import Base, bidirectional_relationship
|
||
|
|
from .contact import ContactForeignKey
|
||
|
|
from .location import LocationForeignKey
|
||
|
|
from .status import StatusForeignKey
|
||
|
|
from .user import Versioned
|
||
|
|
|
||
|
|
|
||
|
|
class PrinterManufacturer(StatusForeignKey, Versioned, Base):
|
||
|
|
"""Printer Manufacturer"""
|
||
|
|
|
||
|
|
code: Mapped[str] = mapped_column(String(10), unique=True)
|
||
|
|
description: Mapped[str] = mapped_column(String(256))
|
||
|
|
notes: Mapped[str | None] = mapped_column(Text)
|
||
|
|
|
||
|
|
|
||
|
|
class PrinterManufacturerForeignKey:
|
||
|
|
"""Foreign Key Mixin for :py:class:`PrinterManufacturer`"""
|
||
|
|
|
||
|
|
printer_manufacturer_id: Mapped[str] = mapped_column(ForeignKey("printer_manufacturer.id"))
|
||
|
|
|
||
|
|
# noinspection PyMethodParameters
|
||
|
|
@declared_attr
|
||
|
|
def printer_manufacturer(cls) -> Mapped["PrinterManufacturer"]:
|
||
|
|
return bidirectional_relationship(cls, PrinterManufacturer)
|
||
|
|
|
||
|
|
|
||
|
|
class PrinterModel(PrinterManufacturerForeignKey, StatusForeignKey, Versioned, Base):
|
||
|
|
"""Printer Model"""
|
||
|
|
|
||
|
|
code: Mapped[str] = mapped_column(String(20), unique=True)
|
||
|
|
description: Mapped[str] = mapped_column(String(256))
|
||
|
|
notes: Mapped[str | None] = mapped_column(Text)
|
||
|
|
|
||
|
|
__table_args__ = (
|
||
|
|
UniqueConstraint('printer_manufacturer_id', code),
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
class PrinterModelForeignKey:
|
||
|
|
"""Foreign Key Mixin for :py:class:`PrinterModel`"""
|
||
|
|
|
||
|
|
printer_model_id: Mapped[str] = mapped_column(ForeignKey("printer_model.id"))
|
||
|
|
|
||
|
|
# noinspection PyMethodParameters
|
||
|
|
@declared_attr
|
||
|
|
def printer_model(cls) -> Mapped["PrinterModel"]:
|
||
|
|
return bidirectional_relationship(cls, PrinterModel)
|
||
|
|
|
||
|
|
|
||
|
|
class Printer(PrinterModelForeignKey, LocationForeignKey, ContactForeignKey, StatusForeignKey, Versioned, Base):
|
||
|
|
"""Printer"""
|
||
|
|
|
||
|
|
name: Mapped[str] = mapped_column(String(63), unique=True)
|
||
|
|
description: Mapped[str] = mapped_column(String(256))
|
||
|
|
notes: Mapped[str | None] = mapped_column(Text)
|
||
|
|
dns_name: Mapped[str | None] = mapped_column(String(253))
|
||
|
|
port: Mapped[int | None]
|
||
|
|
location_detail: Mapped[str] = mapped_column(String(64), default='')
|
||
|
|
|
||
|
|
|
||
|
|
class PrinterForeignKey:
|
||
|
|
"""Foreign Key Mixin for :py:class:`Printer`"""
|
||
|
|
|
||
|
|
printer_id: Mapped[int] = mapped_column(ForeignKey("printer.id"))
|
||
|
|
|
||
|
|
# noinspection PyMethodParameters
|
||
|
|
@declared_attr
|
||
|
|
def printer(cls) -> Mapped["Printer"]:
|
||
|
|
return bidirectional_relationship(cls, Printer)
|