-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmovie.py
More file actions
54 lines (46 loc) · 1.13 KB
/
movie.py
File metadata and controls
54 lines (46 loc) · 1.13 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
from typing import TYPE_CHECKING, Optional
from sqlalchemy import (
ForeignKey,
Identity,
Integer,
String,
Text,
)
from sqlalchemy.orm import (
Mapped,
mapped_column,
relationship,
)
from examples.api_for_sqlalchemy.models.base import Base
if TYPE_CHECKING:
from examples.api_for_sqlalchemy.models.age_rating import AgeRating
class Movie(Base):
__tablename__ = "movie"
id: Mapped[int] = mapped_column(
Integer,
Identity(always=True),
primary_key=True,
autoincrement=True,
)
title: Mapped[str] = mapped_column(
String(120),
index=True,
)
description: Mapped[str] = mapped_column(
Text,
default="",
server_default="",
)
age_rating: Mapped[Optional[str]] = mapped_column(
ForeignKey(
"age_rating.name",
ondelete="SET NULL",
),
)
age_rating_obj: Mapped["AgeRating"] = relationship(
back_populates="movies",
)
def __str__(self) -> str:
return self.title
def __repr__(self) -> str:
return f"Movie(id={self.id}, title={self.title!r})"