add project base
This commit is contained in:
100
backend/src/models.py
Normal file
100
backend/src/models.py
Normal file
@@ -0,0 +1,100 @@
|
||||
from sqlmodel import Field, SQLModel, Relationship
|
||||
from enum import Enum
|
||||
from typing import Optional
|
||||
import datetime
|
||||
|
||||
class Unit(Enum):
|
||||
GRAMS = 1
|
||||
KILO = 2
|
||||
|
||||
class ProductBase(SQLModel):
|
||||
name: str
|
||||
unit: Unit
|
||||
price: float
|
||||
price_kg: float | None
|
||||
weight: float
|
||||
productor_id: int | None = Field(default=None, foreign_key="productor.id")
|
||||
|
||||
class ProductPublic(ProductBase):
|
||||
id: int
|
||||
|
||||
class Product(ProductBase, table=True):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
|
||||
productor: Optional['Productor'] = Relationship(back_populates="products")
|
||||
|
||||
class ProductUpdate(SQLModel):
|
||||
name: str | None
|
||||
unit: Unit | None
|
||||
price: float | None
|
||||
price_kg: float | None
|
||||
weight: float | None
|
||||
productor_id: int | None = Field(default=None, foreign_key="productor.id")
|
||||
|
||||
|
||||
class ProductCreate(ProductBase):
|
||||
pass
|
||||
|
||||
class ProductorBase(SQLModel):
|
||||
name: str
|
||||
address: str
|
||||
payment: str
|
||||
|
||||
class ProductorPublic(ProductorBase):
|
||||
id: int
|
||||
products: list[Product] = []
|
||||
|
||||
class Productor(ProductorBase, table=True):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
|
||||
products: list[Product] = Relationship(back_populates='productor')
|
||||
|
||||
class ProductorUpdate(SQLModel):
|
||||
name: str | None
|
||||
address: str | None
|
||||
payment: str | None
|
||||
|
||||
class ProductorCreate(ProductorBase):
|
||||
pass
|
||||
|
||||
class FormBase(SQLModel):
|
||||
productor_id: int | None = Field(default=None, foreign_key="productor.id")
|
||||
referer_id: int | None = Field(default=None, foreign_key="referer.id")
|
||||
season: str
|
||||
shipments: int
|
||||
start: datetime.date
|
||||
end: datetime.date
|
||||
|
||||
class FormPublic(FormBase):
|
||||
id: int
|
||||
|
||||
class Form(FormBase, table=True):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
|
||||
class FormUpdate(SQLModel):
|
||||
productor_id: int | None = Field(default=None, foreign_key="productor.id")
|
||||
referer_id: int | None = Field(default=None, foreign_key="user.id")
|
||||
season: str | None
|
||||
shipments: int | None
|
||||
start: datetime.date | None
|
||||
end: datetime.date | None
|
||||
|
||||
class FormCreate(FormBase):
|
||||
pass
|
||||
|
||||
class UserBase(SQLModel):
|
||||
name: str
|
||||
email: str
|
||||
|
||||
class UserPublic(UserBase):
|
||||
id: int
|
||||
|
||||
class User(UserBase, table=True):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
|
||||
class UserUpdate(SQLModel):
|
||||
name: str | None
|
||||
email: str | None
|
||||
|
||||
class UserCreate(UserBase):
|
||||
pass
|
||||
Reference in New Issue
Block a user