diff options
| author | l3wdfut4pwr <l3wdfut4pwr@gmail.com> | 2026-03-17 14:11:45 +0200 |
|---|---|---|
| committer | l3wdfut4pwr <l3wdfut4pwr@gmail.com> | 2026-03-17 14:11:45 +0200 |
| commit | 47fd81a5910eab3483f79d03eedf9307bc81252f (patch) | |
| tree | 3e1ebd1bddcea649eb968e65161555afd4c2898c /app/models/image.py | |
| parent | f01cb6703710b7df4c7c022047cd35e1d5e9c70e (diff) | |
simple registration prototype
Diffstat (limited to 'app/models/image.py')
| -rw-r--r-- | app/models/image.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/app/models/image.py b/app/models/image.py new file mode 100644 index 0000000..e139123 --- /dev/null +++ b/app/models/image.py @@ -0,0 +1,70 @@ +from __future__ import annotations + +from datetime import datetime + +from sqlalchemy import ( + Boolean, + Column, + DateTime, + ForeignKey, + Integer, + String, + Table, + func, +) +from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship + +from .collections import Collection + +Base = DeclarativeBase() + +image_tags = Table( + "image_tags", + Base.metadata, + Column("image_id", Integer, ForeignKey("images.id"), primary_key=True), + Column("tag_id", Integer, ForeignKey("tags.id"), primary_key=True), +) + + +class Tag(Base): + __tablename__ = "tags" + + id: Mapped[int] = mapped_column(Integer, primary_key=True) + name: Mapped[str] = mapped_column(String(50), unique=True, nullable=False) + category: Mapped[str | None] = mapped_column(String(50), nullable=True) + + images: Mapped[list["Image"]] = relationship( + "Image", + secondary=image_tags, + back_populates="tags", + ) + + +class Image(Base): + __tablename__ = "images" + + id: Mapped[int] = mapped_column(Integer, primary_key=True) + image_file: Mapped[str] = mapped_column(String(255), nullable=False) + original_file: Mapped[str] = mapped_column(String(255), nullable=False) + user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False) + publication_date: Mapped[datetime] = mapped_column( + DateTime(timezone=True), server_default=func.now() + ) + source: Mapped[str] = mapped_column(String(255), nullable=False) + views: Mapped[int] = mapped_column(Integer, default=0, nullable=False) + likes: Mapped[int] = mapped_column(Integer, default=0, nullable=False) + is_verified: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False) + is_rejected: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False) + + tags: Mapped[list[Tag]] = relationship( + "Tag", + secondary=image_tags, + back_populates="images", + ) + + +collections: Mapped[list["Collection"]] = relationship( + "Collection", + secondary="collection_images", + back_populates="images", +) |
