From a80c7e5faef734b66e882d26b8e5acda9e8b208f Mon Sep 17 00:00:00 2001 From: Matthew Schinckel Date: Wed, 24 Oct 2012 09:37:42 +1030 Subject: [PATCH] Keep the same API (but extend it) for manager methods (they turn into query set methods). --- notifications/models.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/notifications/models.py b/notifications/models.py index ba6d4a2..659f202 100644 --- a/notifications/models.py +++ b/notifications/models.py @@ -18,14 +18,20 @@ except ImportError: now = datetime.datetime.now class NotificationQuerySet(models.query.QuerySet): + def unread(self): + "Return only unread items in the current queryset" return self.filter(unread=True) # Should we return self on these? - def mark_all_as_read(self): + def mark_all_as_read(self, recipient=None): + if recipient: + self.filter(recipient=recipient).update(unread=False) self.update(unread=False) - def mark_all_as_unread(self): + def mark_all_as_unread(self, recipient=None): + if recipient: + self.filter(recipient=recipient).update(unread=True) self.update(unread=True) class Notification(models.Model):