25 lines
912 B
Python
25 lines
912 B
Python
from datetime import datetime
|
|
from typing import Any
|
|
|
|
from ..database import db
|
|
from ..database.types import Serial, UtcDateTime, ModelSerializeMixin
|
|
|
|
|
|
class Notification(db.Model, ModelSerializeMixin):
|
|
__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")
|
|
)
|
|
|
|
@property
|
|
def plugin(self):
|
|
return self.plugin_.name
|