recopytex/backend/model/student.py

29 lines
632 B
Python
Raw Normal View History

2022-12-20 05:59:35 +00:00
from __future__ import annotations
import uuid
from dataclasses import dataclass
from typing import TYPE_CHECKING, Optional
from pydantic import Field
if TYPE_CHECKING:
from backend.model.tribe import Tribe
2022-12-20 05:59:35 +00:00
@dataclass
class Student:
name: str
tribe: Tribe
id: Optional[str] = Field(default_factory=lambda: str(uuid.uuid1()))
2022-12-20 05:59:35 +00:00
def __post_init__(self) -> None:
2022-12-20 05:59:35 +00:00
self.tribe.register_student(self)
def __eq__(self, other: object) -> bool:
if isinstance(other, Student):
return self.id == other.id
return False
def __hash__(self) -> int:
return hash(self.id)