Calendar 모델에 역 관계 정의하기
TimeSlot 모델을 Calendar 모델보다 아래에 배치한 경우 Calendar 클래스를 바로 자료형 각주로 사용할 수 있습니다. Calendar 모델에는 time_slots라는 모델 필드로 역 관계를 맺어 주겠습니다.
파이썬(/appserver/apps/calendar/models.py)
class Calendar(SQLModel, table=True):
__tablename__ = "calendars"
# 생략
host: "User" = Relationship(
back_populates="calendar",
sa_relationship_kwargs={"uselist": False, "single_parent": True},
)
time_slots: list["TimeSlot"] = Relationship(back_populates="calendar")
# Created_at과 Updated_at부터 생략
여기까지 진행한 커밋은 다음 URL을 참고합니다.
https://gilbut.co/c/25069571cS