add contract page with dynamic form elements
This commit is contained in:
@@ -33,7 +33,12 @@ class ProductorPublic(ProductorBase):
|
||||
class Productor(ProductorBase, table=True):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
|
||||
products: list["Product"] = Relationship(back_populates='productor')
|
||||
products: list["Product"] = Relationship(
|
||||
back_populates='productor',
|
||||
sa_relationship_kwargs={
|
||||
"order_by": "Product.name"
|
||||
},
|
||||
)
|
||||
|
||||
class ProductorUpdate(SQLModel):
|
||||
name: str | None
|
||||
@@ -60,9 +65,10 @@ class ShipmentProductLink(SQLModel, table=True):
|
||||
class ProductBase(SQLModel):
|
||||
name: str
|
||||
unit: Unit
|
||||
price: float
|
||||
price: float | None
|
||||
price_kg: float | None
|
||||
weight: float | None
|
||||
quantity: float | None
|
||||
quantity_unit: str | None
|
||||
type: ProductType
|
||||
productor_id: int | None = Field(default=None, foreign_key="productor.id")
|
||||
|
||||
@@ -81,12 +87,13 @@ class ProductUpdate(SQLModel):
|
||||
unit: Unit | None
|
||||
price: float | None
|
||||
price_kg: float | None
|
||||
weight: float | None
|
||||
quantity: float | None
|
||||
quantity_unit: str | None
|
||||
productor_id: int | None
|
||||
shipment_ids: list[int] | None = []
|
||||
type: ProductType | None
|
||||
|
||||
class ProductCreate(ProductBase):
|
||||
shipment_ids: list[int] | None = []
|
||||
pass
|
||||
|
||||
class FormBase(SQLModel):
|
||||
name: str
|
||||
@@ -106,7 +113,13 @@ class Form(FormBase, table=True):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
productor: Optional['Productor'] = Relationship()
|
||||
referer: Optional['User'] = Relationship()
|
||||
shipments: list["Shipment"] = Relationship(back_populates="form", cascade_delete=True)
|
||||
shipments: list["Shipment"] = Relationship(
|
||||
back_populates="form",
|
||||
cascade_delete=True,
|
||||
sa_relationship_kwargs={
|
||||
"order_by": "Shipment.name"
|
||||
},
|
||||
)
|
||||
|
||||
class FormUpdate(SQLModel):
|
||||
name: str | None
|
||||
@@ -161,7 +174,13 @@ class ShipmentPublic(ShipmentBase):
|
||||
|
||||
class Shipment(ShipmentBase, table=True):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
products: list[Product] = Relationship(back_populates="shipments", link_model=ShipmentProductLink)
|
||||
products: list[Product] = Relationship(
|
||||
back_populates="shipments",
|
||||
link_model=ShipmentProductLink,
|
||||
sa_relationship_kwargs={
|
||||
"order_by": "Product.name"
|
||||
},
|
||||
)
|
||||
form: Optional[Form] = Relationship(back_populates="shipments")
|
||||
|
||||
class ShipmentUpdate(SQLModel):
|
||||
|
||||
Reference in New Issue
Block a user