from sqlmodel import SQLModel, Field, Relationship from typing import Optional, List, TYPE_CHECKING # Forward reference for type hinting to avoid circular imports # This is crucial when models reference each other. if TYPE_CHECKING: from .chat import ChatSession # This assumes ChatSession is in chat.py class UserBase(SQLModel): username: str = Field(index=True, unique=True) email: Optional[str] = Field(default=None, index=True, unique=True) full_name: Optional[str] = None disabled: bool = False class User(UserBase, table=True): id: Optional[int] = Field(default=None, primary_key=True) hashed_password: str # ------------ ADDED/CORRECTED SECTION ------------ # This defines the other side of the one-to-many relationship: # A User can have many ChatSession objects. # `back_populates="user"` links this to the `user` attribute in the ChatSession model. chat_sessions: List["ChatSession"] = Relationship(back_populates="user") # ------------------------------------------------- class UserCreate(UserBase): password: str class UserPublic(UserBase): id: int