-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
33 lines (24 loc) · 1.52 KB
/
models.py
File metadata and controls
33 lines (24 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from sqlalchemy import Column, DateTime, Integer, String, ForeignKey
from sqlalchemy.orm import relationship
from database import Base
class User(Base):
__tablename__ = "user"
id = Column(Integer, primary_key=True, index=True, comment="고유번호") # 고유번호
name = Column(String, nullable=False, comment="사용자 이름") # 이름
password = Column(String, nullable=False, comment="비밀번호") # 비밀번호
medication_schedules = relationship("MedicationSchedule", back_populates="user")
class Medication(Base):
__tablename__ = "medication"
id = Column(Integer, primary_key=True, index=True) # 고유번호
name = Column(String, nullable=False, comment="약 이름") # 약 이름
medication_schedules = relationship("MedicationSchedule", back_populates="medication")
class MedicationSchedule(Base):
__tablename__ = "medication_schedule"
id = Column(Integer, primary_key=True, index=True) # 고유번호
user_id = Column(Integer, ForeignKey("user.id"), nullable=False, comment="사용자 ID")
medication_id = Column(Integer, ForeignKey("medication.id"), nullable=False, comment="약 ID")
dosage_mg = Column(String, nullable=False, comment="복용 용량")
scheduled_time = Column(DateTime, nullable=False, comment="복용 예정 시간")
taken_at = Column(DateTime, nullable=True, comment="복용 시각")
user = relationship("User", back_populates="medication_schedules")
medication = relationship("Medication", back_populates="medication_schedules")