"""Item model: a news story managed through the admin area. Unlike ``Article`` (long-form pieces filed under an author and category), an ``Item`` is a lightweight news entry — headline, optional external URL, community points and an optional HTML body — created and maintained by administrators through the admin API (see ``api.v1.admin``). """ from __future__ import annotations from datetime import datetime, timezone from sqlalchemy import DateTime, Integer, String, Text from sqlalchemy.orm import Mapped, mapped_column from models.base import Base def _utcnow() -> datetime: return datetime.now(timezone.utc) class Item(Base): """A news item (story) listed on the front page and managed by admins. ``username`` stores the (denormalized) name of the user the item belongs to, defaulting to the account that created it. """ __tablename__ = "items" id: Mapped[int] = mapped_column(primary_key=True) title: Mapped[str] = mapped_column(String(300), nullable=False, index=True) url: Mapped[str] = mapped_column(String(500), default="", nullable=False) points: Mapped[int] = mapped_column(Integer, default=0, nullable=False) username: Mapped[str] = mapped_column(String(60), default="anonymous", nullable=False) content: Mapped[str] = mapped_column(Text, default="", nullable=False) created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), default=_utcnow, nullable=False ) def __repr__(self) -> str: # pragma: no cover return f""