- PrinterType model: name, bed_x_mm/y/z, linked to Printer via type_id - Migration 0002: creates printer_types, adds type_id to printers, drops model - /printer-types page: table + Add Type modal form - /printers page: Add Printer modal with type dropdown (disabled if no types) - API: GET/POST/DELETE /api/printer-types Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
import enum
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import DateTime, Enum, ForeignKey, String, func
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.models.base import Base
|
|
|
|
|
|
class PrinterStatus(enum.Enum):
|
|
idle = "idle"
|
|
printing = "printing"
|
|
error = "error"
|
|
offline = "offline"
|
|
|
|
|
|
class Printer(Base):
|
|
__tablename__ = "printers"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
name: Mapped[str] = mapped_column(String(100))
|
|
location: Mapped[str | None] = mapped_column(String(100))
|
|
type_id: Mapped[int | None] = mapped_column(ForeignKey("printer_types.id"))
|
|
status: Mapped[PrinterStatus] = mapped_column(
|
|
Enum(PrinterStatus), default=PrinterStatus.offline
|
|
)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime, server_default=func.now(), onupdate=func.now()
|
|
)
|
|
|
|
printer_type: Mapped["PrinterType | None"] = relationship(back_populates="printers")
|
|
jobs: Mapped[list["PrintJob"]] = relationship(back_populates="printer")
|
|
todos: Mapped[list["Todo"]] = relationship(back_populates="printer")
|