mirror of
https://github.com/d3vyce/fastapi-toolsets.git
synced 2026-03-01 17:00:48 +01:00
* docs: fix crud * docs: update README features * docs: add pagination/search example * docs: update zensical.toml * docs: cleanup * docs: update status to Stable + update description * docs: add example run commands
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
import datetime
|
|
import uuid
|
|
|
|
from sqlalchemy import Boolean, DateTime, ForeignKey, String, Text, func
|
|
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
|
|
class Category(Base):
|
|
__tablename__ = "categories"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(primary_key=True, default=uuid.uuid4)
|
|
name: Mapped[str] = mapped_column(String(64), unique=True)
|
|
|
|
articles: Mapped[list["Article"]] = relationship(back_populates="category")
|
|
|
|
|
|
class Article(Base):
|
|
__tablename__ = "articles"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(primary_key=True, default=uuid.uuid4)
|
|
created_at: Mapped[datetime.datetime] = mapped_column(
|
|
DateTime(timezone=True), server_default=func.now()
|
|
)
|
|
title: Mapped[str] = mapped_column(String(256))
|
|
body: Mapped[str] = mapped_column(Text)
|
|
status: Mapped[str] = mapped_column(String(32))
|
|
published: Mapped[bool] = mapped_column(Boolean, default=False)
|
|
category_id: Mapped[uuid.UUID | None] = mapped_column(
|
|
ForeignKey("categories.id"), nullable=True
|
|
)
|
|
|
|
category: Mapped["Category | None"] = relationship(back_populates="articles")
|