diff --git a/notifications/managers.py b/notifications/managers.py deleted file mode 100644 index c4a85d3..0000000 --- a/notifications/managers.py +++ /dev/null @@ -1,9 +0,0 @@ -from django.db import models - - -class NotificationManager(models.Manager): - def unread_count(self, user): - return self.filter(recipient=user, readed=False).count() - - def mark_all_as_read(self, recipient): - return self.filter(recipient=recipient, readed=False).update(readed=True) diff --git a/notifications/models.py b/notifications/models.py index 4fd5bff..d4dedfb 100644 --- a/notifications/models.py +++ b/notifications/models.py @@ -6,15 +6,28 @@ from django.contrib.contenttypes import generic from django.db import models from django.utils.timezone import utc from .utils import id2slug -from notifications.managers import NotificationManager + from notifications.signals import notify +from model_utils import managers + try: from django.utils import timezone now = timezone.now except ImportError: now = datetime.datetime.now +class NotificationQuerySet(models.query.QuerySet): + def unread(self): + return self.filter(unread=True) + + # Should we return self on these? + def mark_all_as_read(self): + self.update(unread=False) + + def mark_all_as_unread(self): + self.update(unread=True) + class Notification(models.Model): """ Action model describing the actor acting out a verb (on an optional @@ -43,9 +56,9 @@ class Notification(models.Model): brosner commented on pinax/pinax 2 hours ago - """ + """ recipient = models.ForeignKey(User, blank=False, related_name='notifications') - readed = models.BooleanField(default=False, blank=False) + unread = models.BooleanField(default=True, blank=False) actor_content_type = models.ForeignKey(ContentType, related_name='notify_actor') actor_object_id = models.CharField(max_length=255) @@ -71,7 +84,7 @@ class Notification(models.Model): public = models.BooleanField(default=True) - objects = NotificationManager() + objects = managers.PassThroughManager.for_queryset_class(NotificationQuerySet)() class Meta: ordering = ('-timestamp', ) diff --git a/notifications/templates/notifications/list.html b/notifications/templates/notifications/list.html index 910243a..21b895f 100644 --- a/notifications/templates/notifications/list.html +++ b/notifications/templates/notifications/list.html @@ -17,7 +17,7 @@