47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
"""Reference data: languages, countries, certifications."""
|
|||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from sqlalchemy import ForeignKey, String, Text, UniqueConstraint
|
||
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||
|
|
|
||
|
|
from app.models.base import Base, TimestampMixin, UUIDPrimaryKeyMixin
|
||
|
|
|
||
|
|
|
||
|
|
class Language(Base):
|
||
|
|
"""ISO 639-1 language codes (e.g. 'en', 'ja')."""
|
||
|
|
|
||
|
|
__tablename__ = "languages"
|
||
|
|
|
||
|
|
code: Mapped[str] = mapped_column(String(10), primary_key=True)
|
||
|
|
english_name: Mapped[str] = mapped_column(String(200), nullable=False)
|
||
|
|
native_name: Mapped[str | None] = mapped_column(String(200), nullable=True)
|
||
|
|
|
||
|
|
|
||
|
|
class Country(Base):
|
||
|
|
"""ISO 3166-1 alpha-2 country codes (e.g. 'US', 'GB')."""
|
||
|
|
|
||
|
|
__tablename__ = "countries"
|
||
|
|
|
||
|
|
code: Mapped[str] = mapped_column(String(2), primary_key=True)
|
||
|
|
name: Mapped[str] = mapped_column(String(200), nullable=False)
|
||
|
|
|
||
|
|
|
||
|
|
class Certification(Base, UUIDPrimaryKeyMixin, TimestampMixin):
|
||
|
|
"""Content rating within a country's rating system, e.g. US/MPA/PG-13."""
|
||
|
|
|
||
|
|
__tablename__ = "certifications"
|
||
|
|
__table_args__ = (
|
||
|
|
UniqueConstraint("country_code", "system", "rating", name="uq_certification_scope"),
|
||
|
|
)
|
||
|
|
|
||
|
|
country_code: Mapped[str] = mapped_column(ForeignKey("countries.code"), nullable=False)
|
||
|
|
system: Mapped[str] = mapped_column(String(50), nullable=False) # e.g. "MPA", "BBFC"
|
||
|
|
rating: Mapped[str] = mapped_column(String(20), nullable=False) # e.g. "PG-13"
|
||
|
|
meaning: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||
|
|
|
||
|
|
country: Mapped[Country] = relationship()
|
||
|
|
|
||
|
|
|
||
|
|
__all__ = ["Language", "Country", "Certification"]
|