Add Photo model and establish relationships with Inventory and User; create worklog_photos association table

This commit is contained in:
Yaro Kasear 2025-07-10 16:15:29 -05:00
parent 54efd370ff
commit 2a8e1710b3
4 changed files with 38 additions and 2 deletions

View file

@ -3,6 +3,7 @@ if TYPE_CHECKING:
from .inventory import Inventory
from .rooms import Room
from .work_log import WorkLog
from .photo import Photo
from sqlalchemy import Boolean, ForeignKey, Identity, Integer, Unicode, text
from sqlalchemy.orm import Mapped, mapped_column, relationship
@ -19,13 +20,14 @@ class User(db.Model):
first_name: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
location_id: Mapped[Optional[int]] = mapped_column(ForeignKey("rooms.id"), nullable=True)
supervisor_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("users.id"))
photo_id: Mapped[Optional[int]] = mapped_column(ForeignKey('photos.id'), nullable=True)
supervisor: Mapped[Optional['User']] = relationship('User', remote_side='User.id', back_populates='subordinates')
subordinates: Mapped[List['User']] = relationship('User', back_populates='supervisor')
work_logs: Mapped[List['WorkLog']] = relationship('WorkLog', back_populates='contact')
location: Mapped[Optional['Room']] = relationship('Room', back_populates='users')
inventory: Mapped[List['Inventory']] = relationship('Inventory', back_populates='owner')
photo: Mapped[Optional['Photo']] = relationship('Photo', back_populates='user')
@property
def full_name(self) -> str: