Skip to content
Discussion options

You must be logged in to vote

You need to create "public" model that reflects db model, but redefines relationship fields (that you want to expose) as follows (use inheritance to reduce code duplication):

class ProductBase(SQLModel): id: str = Field(primary_key=True) ean: str slug: str brand: Optional[str] name: str price: float category_id: int = Field(foreign_key="category.id") description: Optional[str] origin: Optional[str] packaging: Optional[str] unit_name: Optional[str] unit_size: Optional[float] is_variable_weight: bool = False is_pack: bool = False class Product(ProductBase, table=True): images: List["ProductImage"] = Relationship(back_populates="pr…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants