rDrama/files/classes/group_membership.py

30 lines
908 B
Python
Raw Normal View History

2023-02-24 06:31:06 +00:00
import time
2024-02-15 13:17:23 +00:00
from typing import Optional, TYPE_CHECKING
2023-02-24 06:31:06 +00:00
2024-02-15 13:17:23 +00:00
from sqlalchemy import ForeignKey
from sqlalchemy.orm import Mapped, mapped_column, relationship
2023-02-24 06:31:06 +00:00
from files.classes import Base
2024-02-15 21:50:18 +00:00
from files.helpers.types import user_id_fk_pk
2023-02-24 06:31:06 +00:00
2024-02-15 13:17:23 +00:00
if TYPE_CHECKING:
from files.classes.user import User
2023-02-24 06:31:06 +00:00
class GroupMembership(Base):
__tablename__ = "group_memberships"
2024-02-15 21:50:18 +00:00
user_id: Mapped[user_id_fk_pk]
2024-02-15 13:17:23 +00:00
group_name: Mapped[str] = mapped_column(ForeignKey("groups.name"), primary_key=True)
created_utc: Mapped[int]
2024-02-15 13:17:23 +00:00
approved_utc: Mapped[Optional[int]]
2024-02-15 13:17:23 +00:00
is_mod: Mapped[bool] = mapped_column(default=False)
2023-02-24 06:31:06 +00:00
2024-02-15 13:17:23 +00:00
user: Mapped["User"] = relationship(uselist=False)
2023-02-24 06:31:06 +00:00
def __init__(self, *args, **kwargs):
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
super().__init__(*args, **kwargs)
def __repr__(self):
2023-09-13 23:47:50 +00:00
return f"<{self.__class__.__name__}(user_id={self.user_id}, group_name={self.group_name})>"