We have a notification system in place (model extract below) and every time the site needs to notify any user about anything, it creates a notification. Now we want to show that on every site (we use a global template) a counter of the unread messages without changing every view to deliver it to the template. Is there any way to do this right?
class Notification(models.Model):
n_id = models.AutoField(primary_key=True)
n_body = models.CharField(max_length=1000, null=True)
n_recipient = models.ForeignKey(User, related_name='Recipient', on_delete=models.CASCADE)
n_read_status = models.BooleanField(default=False)
Our query would be Notification.objects.filter(n_recipient=request.user, n_read_status=False).count()
but we don't want to call it in every view manually.