-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
40 lines (27 loc) · 794 Bytes
/
example.py
File metadata and controls
40 lines (27 loc) · 794 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
37
38
39
40
from typing import Optional
from pydantic import BaseModel
from cosmopy.model import CosmosModel
class Engine(BaseModel):
hp: int
volume: int
class Car(CosmosModel):
make: str
model: str
engine: Optional[Engine]
if __name__ == "__main__":
passat = Car(make="VW", model="Passat")
print(f"Car: {passat}")
passat.save()
passat.model = "Golf"
golf = passat.save()
print(f"Model changed: {golf}")
passat = Car(make="VW", model="Passat", engine=Engine(hp=100, volume=1600))
passat.save()
print(f"New passat: {passat}")
cars_100_hp = Car.query(engine__hp=100)
print(f"Cars with 100 HP: {cars_100_hp}")
cars = Car.all()
print(f"All cars: {cars}")
for c in cars:
print(f"Deleting: {c}")
c.delete()