diff --git a/aleksis/core/models.py b/aleksis/core/models.py index 8927844a47da2f30e030a9b0815e82539940d8ba..85b16b1e23e597efb14a91803f7515cbdc2195ac 100644 --- a/aleksis/core/models.py +++ b/aleksis/core/models.py @@ -245,6 +245,16 @@ class Person(ExtensibleModel): ) ] + @property + def unread_notifications(self) -> QuerySet: + """Get all unread notifications for this person.""" + return self.notifications.filter(read=False) + + @property + def unread_notifications_count(self) -> int: + """Return the count of unread notifications for this person.""" + return self.unread_notifications.count() + def save(self, *args, **kwargs): super().save(*args, **kwargs) diff --git a/aleksis/core/util/core_helpers.py b/aleksis/core/util/core_helpers.py index 11811b78a493f3b3b2bc6dc0bb63245ce3cf6923..9e9a90faf5547b71f3d556d89d6f2459b743c04b 100644 --- a/aleksis/core/util/core_helpers.py +++ b/aleksis/core/util/core_helpers.py @@ -408,4 +408,4 @@ def queryset_rules_filter( def unread_notifications_badge(request: HttpRequest) -> int: """Generate badge content with the number of unread notifications.""" - return request.user.person.notifications.all().filter(read=False).count() + return request.user.person.unread_notifications_count