mirror of
https://github.com/lemeow125/DocManagerBackend.git
synced 2025-02-23 22:48:14 +08:00
15 lines
531 B
Python
15 lines
531 B
Python
|
from django.db.models.signals import post_save
|
||
|
from django.dispatch import receiver
|
||
|
from datetime import timedelta
|
||
|
from notifications.models import Notification
|
||
|
from django.utils import timezone
|
||
|
|
||
|
|
||
|
@receiver(post_save, sender=Notification)
|
||
|
def notification_post_save(sender, instance, **kwargs):
|
||
|
# Calculate the time threshold (15 minutes ago)
|
||
|
threshold = timezone.now() - timedelta(minutes=15)
|
||
|
|
||
|
# Find and delete all notifications older than 15 minutes
|
||
|
Notification.objects.filter(timestamp__lt=threshold).delete()
|