from app import db
from datetime import datetime

class Notification(db.Model):
    """ A long-term `flash` notification. It is deleted when watched """
    __tablename__ = 'notification'

    id = db.Column(db.Integer, primary_key=True)

    text = db.Column(db.UnicodeText)
    href = db.Column(db.UnicodeText)
    date = db.Column(db.DateTime, default=datetime.now())

    owner_id = db.Column(db.Integer, db.ForeignKey('member.id'),nullable=False)
    owner = db.relationship('Member', backref='notifications',
        foreign_keys=owner_id)

    def __init__(self, owner, text, href=None):
        self.text = text
        self.href = href
        self.owner = owner

    def __repr__(self):
        return f'<Notification to {self.owner.name}: {self.text} ({self.href})>'
