scheme
"/home/yossef/notes/full-stack/python-backend/fastapi/curd_sql/scheme.md"
path: full-stack/python-backend/fastapi/curd_sql/scheme.md
- **fileName**: scheme
- **Created on**: 2025-04-15 17:08:56
starting for the curd system with scheme using pydantic
"""
so now why creating scheme for specify the response type from server
and specific the structure for tables in db and project
"""
from typing import List, Optional
from pydantic import BaseModel
class ItemBase(BaseModel):
title: str
## having a default value with None and Optional provide by user
description: Optional[str] = None
class ItemCreate(ItemBase):
pass
class Item(ItemBase):
id: int
# for owner when create relationship between items and users
owner_id: int
## Enables ORM Integration: This setting tells Pydantic that the model
## should be able to be created from and converted to objects originating
## from an ORM (like SQLAlchemy or Django ORM).
class config:
orm_config = True
class UserBase(BaseModel):
email: str
class UserCreate(UserBase):
password: str
class User(UserCreate):
id: int
is_active: bool
## gone have a list from type Item
items: List[Item] = []
class config:
orm_config = True
# user response value from request
class UserResponse(UserBase):
id: int
hash_password: str
is_active: bool
pydantic reference(BaseModel): pydantic
continue:./database.md
before:./startup.md