-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevent_groups.py
52 lines (41 loc) · 1.86 KB
/
event_groups.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
__all__ = ["EventGroup", "UserXFavoriteEventGroup"]
from typing import Any, TYPE_CHECKING
from sqlalchemy import JSON, ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column, relationship
from src.storages.sql.models.__mixin__ import (
TagsMixinFactory,
IdMixin,
NameMixin,
DescriptionMixin,
OwnershipsMixinFactory,
UpdateCreateDateTimeMixin,
)
from src.storages.sql.models import Base
if TYPE_CHECKING:
from src.storages.sql.models.users import User
from src.storages.sql.models.events import Event
class EventGroup(
Base,
IdMixin,
NameMixin,
DescriptionMixin,
UpdateCreateDateTimeMixin,
TagsMixinFactory("event_groups", Base),
OwnershipsMixinFactory("event_groups", Base),
):
__tablename__ = "event_groups"
alias: Mapped[str] = mapped_column(String(255), unique=True)
path: Mapped[str] = mapped_column(nullable=True, unique=True)
satellite: Mapped[dict[str, Any]] = mapped_column(JSON, nullable=True)
favorites_association: Mapped[list["UserXFavoriteEventGroup"]] = relationship(
"UserXFavoriteEventGroup", back_populates="event_group", cascade="all, delete-orphan", passive_deletes=True
)
events: Mapped[list["Event"]] = relationship("Event", secondary="events_x_event_groups")
class UserXFavoriteEventGroup(Base):
__tablename__ = "users_x_favorite_groups"
user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"), primary_key=True)
group_id: Mapped[int] = mapped_column(ForeignKey("event_groups.id", ondelete="CASCADE"), primary_key=True)
hidden: Mapped[bool] = mapped_column(default=False)
predefined: Mapped[bool] = mapped_column(default=False)
user: Mapped["User"] = relationship("User", back_populates="favorites_association")
event_group: Mapped[EventGroup] = relationship(lazy="joined", back_populates="favorites_association")