Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tags for images, events and news #103

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions db_models/event_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from event_user_model import EventUser_DB
from council_model import Council_DB
from priority_model import Priority_DB
from tag_model import Tag_DB


class Event_DB(BaseModel_DB):
Expand Down Expand Up @@ -42,6 +43,8 @@ class Event_DB(BaseModel_DB):
target_collection="event_users", attr="user", init=False
)

tags: AssociationProxy[list["Tag_DB"]] = association_proxy(target_collection="event_tags", attr="tag", init=False)

priorities: Mapped[list["Priority_DB"]] = relationship(back_populates="event", init=False)

all_day: Mapped[bool] = mapped_column(default=False)
Expand Down
8 changes: 7 additions & 1 deletion db_models/img_model.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from typing import Optional
from typing import Optional, TYPE_CHECKING
from sqlalchemy import ForeignKey
from .album_model import Album_DB
from .base_model import BaseModel_DB
from sqlalchemy.orm import relationship, Mapped, mapped_column
from sqlalchemy.ext.associationproxy import association_proxy, AssociationProxy

if TYPE_CHECKING:
from tag_model import Tag_DB


class Img_DB(BaseModel_DB):
Expand All @@ -15,3 +19,5 @@ class Img_DB(BaseModel_DB):
album_id: Mapped[int] = mapped_column(ForeignKey("album_table.id"), default=None)

album: Mapped["Album_DB"] = relationship(back_populates="imgs", init=False)

tags: AssociationProxy[list["Tag_DB"]] = association_proxy(target_collection="image_tags", attr="tag", init=False)
3 changes: 3 additions & 0 deletions db_models/news_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

from helpers.constants import MAX_NEWS_CONTENT, MAX_NEWS_TITLE
from helpers.db_util import created_at_column
from sqlalchemy.ext.associationproxy import association_proxy, AssociationProxy

if TYPE_CHECKING:
from .user_model import User_DB
from tag_model import Tag_DB


class News_DB(BaseModel_DB):
Expand Down Expand Up @@ -36,5 +38,6 @@ class News_DB(BaseModel_DB):

pinned_to: Mapped[Optional[datetime]] = mapped_column(default=None)

tags: AssociationProxy[list["Tag_DB"]] = association_proxy(target_collection="news_tags", attr="tag", init=False)
# categories: Mapped[list["Category_DB"]]
# image: Mapped["Image_DB"]
29 changes: 29 additions & 0 deletions db_models/tag_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from typing import TYPE_CHECKING

from sqlalchemy import String

from helpers.constants import MAX_TAG_NAME
from .base_model import BaseModel_DB
from sqlalchemy.orm import mapped_column, Mapped
from sqlalchemy.ext.associationproxy import association_proxy, AssociationProxy

if TYPE_CHECKING:
from news_model import News_DB
from event_model import Event_DB
from img_model import Img_DB


class Tag_DB(BaseModel_DB):
__tablename__ = "tag_table"

id: Mapped[int] = mapped_column(primary_key=True, init=False)
tag_name: Mapped[str] = mapped_column(String(MAX_TAG_NAME))
color: Mapped[str] = mapped_column(String(7)) # Defined as #ff0000 for example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


events: AssociationProxy[list["Event_DB"]] = association_proxy(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detta är inte rätt implementerat, ska vara kopplat på annat sätt, skulle läsa att du vill göra typ en EventTags model också istället

target_collection="event_tags", attr="tag", init=False
)

news: AssociationProxy[list["News_DB"]] = association_proxy(target_collection="news_tags", attr="tag", init=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

samma sak som ovam


images: AssociationProxy[list["Img_DB"]] = association_proxy(target_collection="image_tags", attr="tag", init=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

samma sak igen

3 changes: 3 additions & 0 deletions helpers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@

# Imgs
MAX_IMG_NAME = 200

# Tag
MAX_TAG_NAME = 100