add mail to table on notif

This commit is contained in:
2025-06-02 09:17:21 +02:00
parent 17e0781b14
commit 7d08a57c85
8 changed files with 233 additions and 5 deletions

View File

@@ -312,4 +312,23 @@ class EmailTemplate(db.Model):
creator = db.relationship('User', backref='created_email_templates', foreign_keys=[created_by])
def __repr__(self):
return f'<EmailTemplate {self.name}>'
return f'<EmailTemplate {self.name}>'
class Mail(db.Model):
__tablename__ = 'mails'
id = db.Column(db.Integer, primary_key=True)
recipient = db.Column(db.String(150), nullable=False)
subject = db.Column(db.String(200), nullable=False)
body = db.Column(db.Text, nullable=False)
status = db.Column(db.String(20), default='pending', nullable=False) # e.g., pending, sent, failed
created_at = db.Column(db.DateTime, default=datetime.utcnow)
sent_at = db.Column(db.DateTime, nullable=True)
template_id = db.Column(db.Integer, db.ForeignKey('email_templates.id'), nullable=True)
notif_id = db.Column(db.Integer, db.ForeignKey('notifs.id'), nullable=True)
# Relationships
template = db.relationship('EmailTemplate', backref='mails')
notif = db.relationship('Notif', backref='mails')
def __repr__(self):
return f'<Mail to {self.recipient} status={self.status}>'