더북(TheBook)

TimeSlot 모델에 역 관계 정의하기

TimeSlot 모델과 Booking 모델 관계는 1:N이므로 bookings 모델 필드에 대한 자료형 각주는 list["Booking"]으로 정의합니다.

파이썬(/appserver/apps/calendar/models.py)

# 생략
class TimeSlot(SQLModel, table=True):
    __tablename__ = "time_slots"
    # 생략
    calendar: Calendar = Relationship(back_populates="time_slots")

    bookings: list["Booking"] = Relationship(back_populates="time_slot")

 

신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.