63 lines
1.3 KiB
Python
63 lines
1.3 KiB
Python
|
|
import uuid
|
||
|
|
from datetime import datetime
|
||
|
|
from decimal import Decimal
|
||
|
|
|
||
|
|
from pydantic import BaseModel, computed_field
|
||
|
|
|
||
|
|
from app.models.bed import LocationType, SoilType
|
||
|
|
from app.schemas.plant import PlantRead
|
||
|
|
|
||
|
|
|
||
|
|
class BedBase(BaseModel):
|
||
|
|
name: str
|
||
|
|
width_m: Decimal
|
||
|
|
length_m: Decimal
|
||
|
|
location: LocationType
|
||
|
|
soil_type: SoilType = SoilType.NORMAL
|
||
|
|
notes: str | None = None
|
||
|
|
|
||
|
|
|
||
|
|
class BedCreate(BedBase):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
class BedUpdate(BaseModel):
|
||
|
|
name: str | None = None
|
||
|
|
width_m: Decimal | None = None
|
||
|
|
length_m: Decimal | None = None
|
||
|
|
location: LocationType | None = None
|
||
|
|
soil_type: SoilType | None = None
|
||
|
|
notes: str | None = None
|
||
|
|
is_active: bool | None = None
|
||
|
|
|
||
|
|
|
||
|
|
class BedRead(BedBase):
|
||
|
|
model_config = {"from_attributes": True}
|
||
|
|
|
||
|
|
id: uuid.UUID
|
||
|
|
tenant_id: uuid.UUID
|
||
|
|
is_active: bool
|
||
|
|
created_at: datetime
|
||
|
|
updated_at: datetime
|
||
|
|
|
||
|
|
@computed_field
|
||
|
|
@property
|
||
|
|
def area_m2(self) -> Decimal:
|
||
|
|
return self.width_m * self.length_m
|
||
|
|
|
||
|
|
|
||
|
|
class PlantingInBed(BaseModel):
|
||
|
|
model_config = {"from_attributes": True}
|
||
|
|
|
||
|
|
id: uuid.UUID
|
||
|
|
plant: PlantRead
|
||
|
|
area_m2: Decimal | None
|
||
|
|
count: int | None
|
||
|
|
planted_date: datetime | None = None
|
||
|
|
removed_date: datetime | None = None
|
||
|
|
notes: str | None = None
|
||
|
|
|
||
|
|
|
||
|
|
class BedDetailRead(BedRead):
|
||
|
|
plantings: list[PlantingInBed] = []
|