28 lines
No EOL
910 B
Python
28 lines
No EOL
910 B
Python
from typing import List, Optional, TYPE_CHECKING
|
|
if TYPE_CHECKING:
|
|
from .rooms import Room
|
|
|
|
from sqlalchemy import Identity, Integer, Unicode
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from . import db
|
|
|
|
class RoomFunction(db.Model):
|
|
__tablename__ = 'Room Functions'
|
|
|
|
id: Mapped[int] = mapped_column("ID", Integer, Identity(start=1, increment=1), primary_key=True)
|
|
description: Mapped[Optional[str]] = mapped_column("Function", Unicode(255), nullable=True)
|
|
|
|
rooms: Mapped[List['Room']] = relationship('Room', back_populates='room_function')
|
|
|
|
def __init__(self, description: Optional[str] = None):
|
|
self.description = description
|
|
|
|
def __repr__(self):
|
|
return f"<RoomFunction(id={self.id}, description={repr(self.description)})>"
|
|
|
|
def serialize(self):
|
|
return {
|
|
'id': self.id,
|
|
'name': self.description
|
|
} |