The rest of the models.

This commit is contained in:
Yaro Kasear 2025-09-04 15:11:33 -05:00
parent b990805566
commit 8643d177ca
2 changed files with 41 additions and 0 deletions

View file

@ -0,0 +1,25 @@
from typing import List, Optional
from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, Unicode
from sqlalchemy.orm import Mapped, mapped_column, relationship
from crudkit.core.base import Base, CRUDMixin
class WorkLog(Base, CRUDMixin):
__tablename__ = "work_log"
start_time: Mapped[Optional[DateTime]] = mapped_column(DateTime)
end_time: Mapped[Optional[DateTime]] = mapped_column(DateTime)
complete: Mapped[Optional[bool]] = mapped_column(Boolean, nullable=False, default=False)
contact: Mapped[Optional['User']] = relationship('User', back_populates='work_logs')
contact_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("user.id"), nullable=True, index=True)
updates: Mapped[List['WorkNote']] = relationship('WorkNote', back_populates='work_log', cascade='all, delete-orphan')
work_item: Mapped[Optional['Inventory']] = relationship('Inventory', back_populates='work_logs')
work_item_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey('inventory.id'), nullable=True, index=True)
def __repr__(self):
return f"<WorkLog(id={self.id}, contact={repr(self.contact.first_name)} {repr(self.contact.last_name)})>"

View file

@ -0,0 +1,16 @@
from sqlalchemy import DateTime, UnicodeText, func
from sqlalchemy.orm import Mapped, mapped_column, relationship
from crudkit.core.base import Base, CRUDMixin
class WorkNote(Base, CRUDMixin):
__tablename__ = "work_note"
content: Mapped[str] = mapped_column(UnicodeText, nullable=False)
timestamp: Mapped[DateTime] = mapped_column(DateTime, default=func.now(), server_default=func.now())
work_log: Mapped['WorkLog'] = relationship('WorkLog', back_populates='updates')
def __repr__(self) -> str:
preview = self.content[:30].replace("\n", " ") + "..." if len(self.content) > 30 else self.content
return f"<WorkNote(id={self.id}), log_id={self.work_log_id}, ts={self.timestamp}, content={preview!r}>"