-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmovie.py
More file actions
60 lines (45 loc) · 1.24 KB
/
movie.py
File metadata and controls
60 lines (45 loc) · 1.24 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
59
60
from datetime import date
from typing import (
TYPE_CHECKING,
Annotated,
Optional,
)
from annotated_types import MaxLen, MinLen
from pydantic import ConfigDict
from fastapi_jsonapi.schema_base import BaseModel
from fastapi_jsonapi.types_metadata import RelationshipInfo
if TYPE_CHECKING:
from examples.api_for_sqlalchemy.schemas.age_rating import AgeRatingSchema
title_constrained = Annotated[
str,
MinLen(1),
MaxLen(120),
]
class MovieAttributesSchema(BaseModel):
model_config = ConfigDict(
from_attributes=True,
)
title: str
description: str
age_rating: Optional[str] = None
class MovieBaseSchema(MovieAttributesSchema):
age_rating_obj: Annotated[
Optional["AgeRatingSchema"],
RelationshipInfo(
resource_type="age-rating",
resource_id_example="PG-13",
id_field_name="name",
),
] = None
class MovieCreateSchema(MovieBaseSchema):
"""
Create
"""
title: title_constrained
class MovieUpdateSchema(MovieBaseSchema):
title: Optional[title_constrained] = None
description: Optional[str] = None
release_date: Optional[date] = None
duration: Optional[int] = None
class MovieSchema(MovieBaseSchema):
id: int