24 lines
729 B
Python
24 lines
729 B
Python
"""
|
|
Author model for Newzy application.
|
|
"""
|
|
|
|
from datetime import datetime
|
|
from sqlalchemy import ForeignKey, Integer, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from db.session import Base
|
|
|
|
|
|
class Author(Base):
|
|
"""Represents an article author."""
|
|
|
|
__tablename__ = "authors"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
|
name: Mapped[str] = mapped_column(String(100), unique=True, nullable=False)
|
|
email: Mapped[str] = mapped_column(String(255), unique=True, nullable=False)
|
|
bio: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
|
|
# Relationships
|
|
articles: Mapped[list["Article"]] = relationship("Article", back_populates="author")
|