Pydantic model
You've been asked to create an API endpoint that manages items in inventory. To get started, create a Pydantic model for Items that has attributes name, quantity, and expiration.
Este ejercicio forma parte del curso
Introduction to FastAPI
Instrucciones del ejercicio
- Import
datefromdatetimeandBaseModelfrompydantic. - Create a Pydantic model for
Item. - Fill in the following fields correctly:
name(string),quantity(integer, optional, default 0), andexpiration(date, optional, default None).
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Import date
from datetime import ____
# Import BaseModel
from pydantic import ____
# Define model Item
class Item(____):
name: str
____: int = 0
expiration: ____ = None