More models added.

This commit is contained in:
Yaro Kasear 2025-09-04 11:45:29 -05:00
parent cc13321bbc
commit b990805566
2 changed files with 52 additions and 1 deletions

View file

@ -1,4 +1,24 @@
from typing import List, Optional
from sqlalchemy import ForeignKey, Integer, Unicode
from sqlalchemy.orm import Mapped, mapped_column, relationship
from crudkit.core.base import Base, CRUDMixin
class Room(Base, CRUDMixin):
__tablename__ = 'rooms'
__tablename__ = 'rooms'
name: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
area: Mapped[Optional['Area']] = relationship('Area', back_populates='rooms')
area_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("area.id"), nullable=True, index=True)
inventory: Mapped[List['Inventory']] = relationship('Inventory', back_populates='location')
users: Mapped[List['User']] = relationship('User', back_populates='location')
room_function: Mapped[Optional['RoomFunction']] = relationship('RoomFunction', back_populates='rooms')
room_function_id: Mapped[Optional[int]] = mapped_column('function_id', Integer, ForeignKey("room_function.id"), nullable=True, index=True)
def __repr__(self):
return f"<Room(id={self.id}, name={repr(self.name)}, area={repr(self.area.name)}, function={repr(self.room_function.description)})>"

31
inventory/models/user.py Normal file
View file

@ -0,0 +1,31 @@
from typing import List, Optional
from sqlalchemy import Boolean, Integer, ForeignKey, Unicode
from sqlalchemy.orm import Mapped, mapped_column, relationship
from crudkit.core.base import Base, CRUDMixin
class User(Base, CRUDMixin):
__tablename__ = 'users'
first_name: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
last_name: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
title: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
active: Mapped[Optional[bool]] = mapped_column(Boolean, nullable=False, default=False)
staff: Mapped[Optional[bool]] = mapped_column(Boolean, nullable=False, default=False)
image: Mapped[Optional['Image']] = relationship('Image', back_populates='user', passive_deletes=True)
image_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("images.id", ondelete="SET NULL"), nullable=True, index=True)
inventory: Mapped[List['Inventory']] = relationship('Inventory', back_populates='owner')
location: Mapped[Optional['Room']] = relationship('Room', back_populates='owner')
location_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("users.id"), nullable=True, index=True)
supervisor: Mapped[Optional['User']] = relationship('User', back_populates='subordinates')
supervisor_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("user.id"), nullable=True, index=True)
subordinates: Mapped[List['User']] = relationship('User', back_populates='supervisor')
def __repr__(self):
return f"<User(id={self.id}, first_name={repr(self.first_name)}, last_name={repr(self.last_name)})>"