From 01c06cced8087758c0e151c71032665f70f560b8 Mon Sep 17 00:00:00 2001 From: Adarnof Date: Fri, 10 Jun 2016 22:12:39 -0400 Subject: [PATCH] max number of notifications per user deletes oldest once surpassed closes #368 --- notifications/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/notifications/__init__.py b/notifications/__init__.py index dedd2956..67bb4cca 100644 --- a/notifications/__init__.py +++ b/notifications/__init__.py @@ -3,7 +3,12 @@ import logging logger = logging.getLogger(__name__) +MAX_NOTIFICATIONS = 50 + def notify(user, title, message=None, level='info'): + if Notification.objects.filter(user=user).count() > MAX_NOTIFICATIONS: + for n in Notification.objects.filter(user=user)[MAX_NOTIFICATIONS:]: + n.delete() notif = Notification() notif.user = user notif.title = title