mirror of
https://github.com/Hopiu/django-notifications.git
synced 2026-05-17 17:21:06 +00:00
Document/clean-up query set API.
This commit is contained in:
parent
a37250431b
commit
d02c7893ac
1 changed files with 23 additions and 7 deletions
|
|
@ -23,18 +23,34 @@ class NotificationQuerySet(models.query.QuerySet):
|
|||
"Return only unread items in the current queryset"
|
||||
return self.filter(unread=True)
|
||||
|
||||
# Should we return self on these?
|
||||
def read(self):
|
||||
"Return only read items in the current queryset"
|
||||
return self.filter(unread=False)
|
||||
|
||||
def mark_all_as_read(self, recipient=None):
|
||||
"""Mark as read any unread messages in the current queryset.
|
||||
|
||||
Optionally, filter these by recipient first.
|
||||
"""
|
||||
# We want to filter out read ones, as later we will store
|
||||
# the time they were marked as read.
|
||||
qs = self.unread()
|
||||
if recipient:
|
||||
self.filter(recipient=recipient).update(unread=False)
|
||||
else:
|
||||
self.update(unread=False)
|
||||
qs = qs.filter(recipient=recipient)
|
||||
|
||||
qs.update(unread=False)
|
||||
|
||||
def mark_all_as_unread(self, recipient=None):
|
||||
"""Mark as unread any read messages in the current queryset.
|
||||
|
||||
Optionally, filter these by recipient first.
|
||||
"""
|
||||
qs = self.read()
|
||||
|
||||
if recipient:
|
||||
self.filter(recipient=recipient).update(unread=True)
|
||||
else:
|
||||
self.update(unread=True)
|
||||
qs = qs.filter(recipient=recipient)
|
||||
|
||||
qs.update(unread=True)
|
||||
|
||||
class Notification(models.Model):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue