Inventory model. Ugh.

This commit is contained in:
Yaro Kasear 2025-09-04 10:04:11 -05:00
parent 388472742e
commit a76d19706c

View file

@ -1,18 +1,54 @@
from typing import Optional from typing import Optional
from sqlalchemy import DateTime, ForeignKey, Index, Integer, Unicode from sqlalchemy import Boolean, DateTime, ForeignKey, Index, Integer, Unicode
from sqlalchemy.orm import Mapped, mapped_column from sqlalchemy.orm import Mapped, mapped_column, relationship
from crudkit.core.base import Base, CRUDMixin from crudkit.core.base import Base, CRUDMixin
class Inventory(Base, CRUDMixin): class Inventory(Base, CRUDMixin):
__tablename__ = "inventory" __tablename__ = "inventory"
barcode: Mapped[Optional[str]] = mapped_column(Unicode(255))
name: Mapped[Optional[str]] = mapped_column(Unicode(255)) name: Mapped[Optional[str]] = mapped_column(Unicode(255))
serial: Mapped[Optional[str]] = mapped_column(Unicode(255)) serial: Mapped[Optional[str]] = mapped_column(Unicode(255))
timestamp: Mapped[DateTime] = mapped_column(DateTime)
condition: Mapped[str] = mapped_column(Unicode(255)) condition: Mapped[str] = mapped_column(Unicode(255))
model: Mapped[Optional[str]] = mapped_column(Unicode(255))
notes: Mapped[Optional[str]] = mapped_column(Unicode(255))
shared = Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
timestamp: Mapped[DateTime] = mapped_column(DateTime)
brand: Mapped[Optional['Brand']] = relationship('Brand', back_populates='inventory')
brand_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey('users.id'), nullable=True, index=True)
device_type: Mapped[Optional['DeviceType']] = relationship('DeviceType', back_populates='inventory')
device_type_id: Mapped[Optional[int]] = mapped_column('type_id', Integer, ForeignKey("item.id"), nullable=True, index=True) device_type_id: Mapped[Optional[int]] = mapped_column('type_id', Integer, ForeignKey("item.id"), nullable=True, index=True)
device_type: Mapped[Optional['DeviceType']]
image: Mapped[Optional['Image']] = relationship('Image', back_populates='inventory', passive_deletes=True)
image_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey('images.id', ondelete='SET NULL'), nullable=True, index=True)
location = Mapped[Optional['Room']] = relationship('Room', back_populates='inventory')
location_id = Mapped[Optional[int]] = mapped_column(Integer, ForeignKey('rooms.id'), nullable=True, index=True)
owner: Mapped[Optional['User']] = relationship('User', back_populates='inventory')
owner_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("users.id"), nullable=True, index=True)
def __repr__(self):
parts = [f"id={self.id}"]
if self.name:
parts.append(f"name={repr(self.name)}")
if self.device_type:
parts.append(f"item={repr(self.device_type.description)}")
if self.notes:
parts.append(f"notes={repr(self.notes)}")
if self.owner:
parts.append(f"owner={repr(self.owner.identifier)}")
if self.location:
parts.append(f"location={repr(self.location.identifier)}")
return f"<Inventory({', '.join(parts)})>"