27 lines
1.2 KiB
Python
27 lines
1.2 KiB
Python
from typing import List, Optional, TYPE_CHECKING
|
|
|
|
from sqlalchemy import ForeignKey, Integer, Unicode
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from crudkit.core.base import Base, CRUDMixin
|
|
|
|
if TYPE_CHECKING:
|
|
from .user import User
|
|
|
|
class Room(Base, CRUDMixin):
|
|
__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)})>"
|