models.py 파일을 만들고 기본 구성 요소 정의하기
먼저 account 앱 디렉터리 안에 models.py 파일을 만들고 다음 내용을 작성합니다.
파이썬(/appserver/apps/account/models.py)
from datetime import datetime
from sqlmodel import SQLModel, Field
from pydantic import EmailStr
from sqlalchemy import UniqueConstraint
class User(SQLModel, table=True):
__tablename__ = "users" # ①
__table_args__ = (
UniqueConstraint("email", name="uq_email"), # ④
)
id: int = Field(default=None, primary_key=True) # ②
username: str = Field(unique=True, max_length=40, description="사용자 계정 ID") # ③
email: EmailStr = Field(max_length=128, description="사용자 이메일")
display_name: str = Field(max_length=40, description="사용자 표시 이름") # ⑤
password: str = Field(max_length=128, description="사용자 비밀번호")
is_host: bool = Field(default=False, description="사용자가 호스트인지 여부")
created_at: datetime # ⑥
updated_at: datetime # ⑥
코드에서 주요 항목들을 하나씩 살펴보겠습니다.