Files
n3wt-school/Back-End/GestionNotification/signals.py
2025-01-12 10:07:06 +01:00

24 lines
898 B
Python

from django.db.models.signals import post_save
from django.dispatch import receiver
from .models import Notification, TypeNotif
from GestionMessagerie.models import Messagerie
from Subscriptions.models import RegistrationForm
@receiver(post_save, sender=Messagerie)
def notification_MESSAGE(sender, instance, created, **kwargs):
if created:
Notification.objects.create(
user=instance.destinataire,
message=(TypeNotif.NOTIF_MESSAGE).label,
typeNotification=TypeNotif.NOTIF_MESSAGE
)
@receiver(post_save, sender=RegistrationForm)
def notification_DI(sender, instance, created, **kwargs):
for responsable in instance.student.guardians.all():
Notification.objects.create(
user=responsable.associated_profile,
message=(TypeNotif.NOTIF_DI).label,
typeNotification=TypeNotif.NOTIF_DI
)