from __future__ import annotations # TODO: Remove if python requirement is >= 3.12 (? PEP 563 is defered) from datetime import datetime from typing import Any from ..database import db from ..database.types import Serial, UtcDateTime, ModelSerializeMixin class Notification(db.Model, ModelSerializeMixin): __allow_unmapped__ = True __tablename__ = "notification" id: int = db.Column("id", Serial, primary_key=True) text: str = db.Column(db.Text) data: Any = db.Column(db.PickleType(protocol=4)) time: datetime = db.Column(UtcDateTime, nullable=False, default=UtcDateTime.current_utc) user_id_: int = db.Column("user", Serial, db.ForeignKey("user.id"), nullable=False) plugin_id_: int = db.Column("plugin", Serial, db.ForeignKey("plugin.id"), nullable=False) user_: User = db.relationship("User") plugin_: Plugin = db.relationship( "Plugin", backref=db.backref("notifications_", cascade="all, delete, delete-orphan") ) plugin: str @property def plugin(self) -> str: return self.plugin_.name