35 lines
929 B
Python
35 lines
929 B
Python
Here's the `user.py` file with Pydantic schemas for the `User` model, which you can place in the `app/api/v1/schemas/` directory:
|
|
|
|
from typing import Optional
|
|
from pydantic import BaseModel, EmailStr
|
|
|
|
class UserBase(BaseModel):
|
|
email: Optional[EmailStr] = None
|
|
is_active: Optional[bool] = True
|
|
is_superuser: bool = False
|
|
full_name: Optional[str] = None
|
|
|
|
class UserCreate(UserBase):
|
|
email: EmailStr
|
|
password: str
|
|
|
|
class UserUpdate(UserBase):
|
|
password: Optional[str] = None
|
|
|
|
class UserInDBBase(UserBase):
|
|
id: Optional[int] = None
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
|
|
class User(UserInDBBase):
|
|
pass
|
|
|
|
class UserInUpdate(UserUpdate):
|
|
pass
|
|
|
|
This file defines several Pydantic models for the `User` model:
|
|
|
|
|
|
|
|
Note: This code assumes that you have the `pydantic` library installed and that your project follows the recommended structure for FastAPI applications using SQLAlchemy and SQLite. |