Task-Flow-App / src /models /user.py
Tahasaif3's picture
'code'
0d42de6
Raw History Blame
1.03 kB
from sqlmodel import SQLModel, Field, Relationship
from typing import Optional, List
import uuid
from datetime import datetime
from sqlalchemy import Column, DateTime
class UserBase(SQLModel):
email: str = Field(unique=True, index=True, max_length=255)
class User(UserBase, table=True):
id: Optional[uuid.UUID] = Field(default_factory=uuid.uuid4, primary_key=True)
email: str = Field(unique=True, index=True, max_length=255)
password_hash: str = Field(max_length=255)
created_at: datetime = Field(sa_column=Column(DateTime, default=datetime.utcnow))
updated_at: datetime = Field(sa_column=Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow))
# Relationship to tasks
tasks: List["Task"] = Relationship(back_populates="owner")
# Relationship to projects
projects: List["Project"] = Relationship(back_populates="owner")
class UserCreate(UserBase):
password: str
class UserRead(UserBase):
id: uuid.UUID
created_at: datetime
updated_at: datetime