-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathrelationships_info_example.py
More file actions
58 lines (44 loc) · 1.12 KB
/
relationships_info_example.py
File metadata and controls
58 lines (44 loc) · 1.12 KB
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
from __future__ import annotations
from typing import Annotated
from pydantic import BaseModel as PydanticBaseModel, ConfigDict
from fastapi_jsonapi.types_metadata import RelationshipInfo
class BaseModel(PydanticBaseModel):
model_config = ConfigDict(from_attributes=True)
class UserBaseSchema(BaseModel):
id: int
name: str
bio: Annotated[
UserBioSchema | None,
RelationshipInfo(
resource_type="user_bio",
),
]
computers: Annotated[
ComputerSchema | None,
RelationshipInfo(
resource_type="computer",
many=True,
),
]
class UserSchema(BaseModel):
id: int
name: str
class UserBioSchema(BaseModel):
birth_city: str
favourite_movies: str
# keys_to_ids_list: Optional[dict[str, list[int]]] = None
user: Annotated[
UserSchema | None,
RelationshipInfo(
resource_type="user",
),
]
class ComputerSchema(BaseModel):
id: int
name: str
user: Annotated[
UserSchema | None,
RelationshipInfo(
resource_type="user",
),
]