Spaces:
Sleeping
Sleeping
File size: 896 Bytes
697c967 |
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 |
from sqlmodel import SQLModel, Field, Relationship
from typing import Optional, List
from datetime import datetime
class UserBase(SQLModel):
email: str = Field(unique=True, nullable=False, max_length=255)
name: str = Field(nullable=False, max_length=255)
class User(UserBase, table=True):
"""
Represents a registered user in the system with authentication information.
"""
__tablename__ = "users" # Use 'users' instead of 'user' to avoid PostgreSQL reserved keyword
id: Optional[int] = Field(default=None, primary_key=True)
created_at: datetime = Field(default_factory=datetime.utcnow)
# Relationship to tasks
tasks: List["Task"] = Relationship(back_populates="user")
class UserCreate(UserBase):
"""Schema for creating a new user."""
pass
class UserRead(UserBase):
"""Schema for reading user data."""
id: int
created_at: datetime |