5
5
from typing import Optional , List
6
6
7
7
from geoalchemy2 .shape import to_shape
8
- from pydantic import BaseModel
8
+ from pydantic import ConfigDict , BaseModel
9
9
10
10
from app import models
11
11
@@ -33,31 +33,29 @@ class School(BaseModel):
33
33
id : str
34
34
name : str
35
35
address : str
36
- address2 : Optional [str ]
37
- city : Optional [str ]
38
- director : Optional [str ]
39
- email : Optional [str ]
40
- fax : Optional [str ]
41
- latitude : Optional [float ]
42
- legal_status : Optional [str ]
43
- longitude : Optional [float ]
44
- phone : Optional [str ]
45
- provider : Optional [str ]
46
- school_type : Optional [str ]
47
- website : Optional [str ]
48
- zip : Optional [str ]
49
- raw : Optional [dict ]
50
- update_timestamp : Optional [datetime ]
51
-
52
- class Config :
53
- orm_mode = True
36
+ address2 : Optional [str ] = None
37
+ city : Optional [str ] = None
38
+ director : Optional [str ] = None
39
+ email : Optional [str ] = None
40
+ fax : Optional [str ] = None
41
+ latitude : Optional [float ] = None
42
+ legal_status : Optional [str ] = None
43
+ longitude : Optional [float ] = None
44
+ phone : Optional [str ] = None
45
+ provider : Optional [str ] = None
46
+ school_type : Optional [str ] = None
47
+ website : Optional [str ] = None
48
+ zip : Optional [str ] = None
49
+ raw : Optional [dict ] = None
50
+ update_timestamp : Optional [datetime ] = None
51
+ model_config = ConfigDict (from_attributes = True )
54
52
55
53
@staticmethod
56
54
def from_db (db_entry : models .School ) -> School :
57
55
if not db_entry .location :
58
- return School .from_orm (db_entry )
56
+ return School .model_validate (db_entry )
59
57
shape = to_shape (db_entry .location )
60
- school = School .from_orm (db_entry )
58
+ school = School .model_validate (db_entry )
61
59
school .latitude = shape .x
62
60
school .longitude = shape .y
63
61
return school
@@ -66,17 +64,15 @@ def from_db(db_entry: models.School) -> School:
66
64
class Statistic (BaseModel ):
67
65
state : State
68
66
count : int
69
-
70
- class Config :
71
- schema_extra = {
72
- "example" : [{
73
- "name" : "BE" ,
74
- "count" : 10 ,
75
- },
76
- {"name" : "ND" ,
77
- "count" : 12 }
78
- ]
79
- }
67
+ model_config = ConfigDict (json_schema_extra = {
68
+ "example" : [{
69
+ "name" : "BE" ,
70
+ "count" : 10 ,
71
+ },
72
+ {"name" : "ND" ,
73
+ "count" : 12 }
74
+ ]
75
+ })
80
76
81
77
82
78
class Params (BaseModel ):
0 commit comments