Files
yellow-bank-soal/app/models/website.py
Dwindi Ramadhana cf193d7ea0 first commit
2026-03-21 23:32:59 +07:00

70 lines
1.9 KiB
Python

"""
Website model for multi-site support.
Represents WordPress websites that use the IRT Bank Soal system.
"""
from datetime import datetime
from sqlalchemy import DateTime, String
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.database import Base
class Website(Base):
"""
Website model representing WordPress sites.
Enables multi-site support where a single backend serves multiple
WordPress-powered educational sites.
Attributes:
id: Primary key
site_url: WordPress site URL
site_name: Human-readable site name
created_at: Record creation timestamp
updated_at: Record update timestamp
users: Users belonging to this website
tryouts: Tryouts available on this website
"""
__tablename__ = "websites"
# Primary key
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
# Site information
site_url: Mapped[str] = mapped_column(
String(512),
nullable=False,
unique=True,
index=True,
comment="WordPress site URL",
)
site_name: Mapped[str] = mapped_column(
String(255), nullable=False, comment="Human-readable site name"
)
# Timestamps
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, server_default="NOW()"
)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
nullable=False,
server_default="NOW()",
onupdate="NOW()",
)
# Relationships
users: Mapped[list["User"]] = relationship(
"User", back_populates="website", lazy="selectin", cascade="all, delete-orphan"
)
tryouts: Mapped[list["Tryout"]] = relationship(
"Tryout", back_populates="website", lazy="selectin", cascade="all, delete-orphan"
)
def __repr__(self) -> str:
return f"<Website(id={self.id}, site_url={self.site_url})>"