Files
newz-qwen-9b/backend/models/article.py
T

28 lines
1.0 KiB
Python

"""
Article model for Newzy application.
"""
from datetime import datetime
from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column, relationship
from db.session import Base
class Article(Base):
"""Represents a news article."""
__tablename__ = "articles"
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
title: Mapped[str] = mapped_column(String(200), unique=True, nullable=False)
content: Mapped[str] = mapped_column(Text, nullable=False)
author_id: Mapped[int] = mapped_column(ForeignKey("authors.id"), nullable=False)
category_id: Mapped[int] = mapped_column(ForeignKey("categories.id"), nullable=False)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
published: Mapped[bool] = mapped_column(Boolean, default=False)
# Relationships
author: Mapped["Author"] = relationship("Author", back_populates="articles")
category: Mapped["Category"] = relationship("Category", back_populates="articles")