-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrelationships_info_example.py
60 lines (47 loc) · 1.31 KB
/
relationships_info_example.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from typing import Optional
from pydantic import BaseModel as PydanticBaseModel, ConfigDict
from fastapi_jsonapi.schema_base import Field, RelationshipInfo
class BaseModel(PydanticBaseModel):
model_config = ConfigDict(from_attributes=True)
class UserBaseSchema(BaseModel):
id: int
name: str
bio: Optional["UserBioSchema"] = Field(
json_schema_extra={
"relationship": RelationshipInfo(
resource_type="user_bio",
),
},
)
computers: Optional["ComputerSchema"] = Field(
json_schema_extra={
"relationship": RelationshipInfo(
resource_type="computer",
many=True,
),
},
)
class UserSchema(BaseModel):
id: int
name: str
class UserBioBaseSchema(BaseModel):
birth_city: str
favourite_movies: str
keys_to_ids_list: dict[str, list[int]] = None
user: "UserSchema" = Field(
json_schema_extra={
"relationship": RelationshipInfo(
resource_type="user",
),
},
)
class ComputerBaseSchema(BaseModel):
id: int
name: str
user: Optional["UserSchema"] = Field(
json_schema_extra={
"relationship": RelationshipInfo(
resource_type="user",
),
},
)