Skip to content

Instantly share code, notes, and snippets.

@laurent-laporte-pro
Created May 24, 2023 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laurent-laporte-pro/2a9ad1f463c9791ab61840c73b7b4cc8 to your computer and use it in GitHub Desktop.
Save laurent-laporte-pro/2a9ad1f463c9791ab61840c73b7b4cc8 to your computer and use it in GitHub Desktop.
Advanced Pydantic model -- example of "product" with INI parameters
from enum import Enum
from pydantic import Field
from antarest.study.business.utils import FormFieldsBaseModel
class SizeEnum(str, Enum):
SMALL = "Small"
MEDIUM = "Medium"
LARGE = "Large"
class Product(FormFieldsBaseModel):
name: str = Field(description="The name of the product")
price: float = Field(
gt=0,
description="The price of the product (in euro)",
ini_path="product-price",
)
quantity: int = Field(
1,
gt=0,
description="The available quantity of the product",
ini_path="qty",
start_version=810,
)
product_size: SizeEnum = Field(
SizeEnum.SMALL,
description="The size of the product",
start_version=810,
end_version=820,
ini_path="product-size",
)
# Example usage
product_data = {
"name": "Example Product",
"price": 9.99,
"quantity": 100,
"productSize": "Medium",
}
product = Product(**product_data)
print(product)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment