-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathmodels.py
More file actions
36 lines (29 loc) · 992 Bytes
/
models.py
File metadata and controls
36 lines (29 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# from dataclasses import dataclass
from typing import Optional
from sqlmodel import SQLModel, Field
from pydantic import validator
# from sqlmodel import select
from statistics import mean
from datetime import datetime
class Beer(SQLModel, table=True):
id: Optional[int] = Field(primary_key=True, default=None, index=True)
name: str
style: str
flavor: int
image: int
cost: int
rate: int = 0
date: datetime = Field(default_factory=datetime.now)
@validator("flavor", "image", "cost")
def validade_rating(cls, v, field):
if v < 1 or v > 10:
raise RuntimeError(f"{field.name} must be between 1 and 10")
return v
@validator("rate", always=True)
def calculate_rate(cls, v, values):
rate = mean([values["flavor"], values["image"], values["cost"]])
return int(rate)
# try:
brewdog = Beer(name="Brewdog", style="NEIPA", flavor=6, image=8, cost=10)
# except RuntimeError:
# print("deu zica demais")