Source code for apps.notifications.models

from django.db import models
from django.utils.translation import gettext_lazy as _

from apps.notifications.constants import NotificationTypeChoices
from apps.posts.models import Post
from apps.users.models import User


[docs] class Notification(models.Model): """Notification Model""" receiver = models.ForeignKey( User, on_delete=models.CASCADE, verbose_name=_("Receiver"), related_name="notifications" ) type = models.CharField(_("Type"), max_length=100, choices=NotificationTypeChoices.choices) is_read = models.BooleanField(_("Is read"), default=False) post = models.ForeignKey( Post, on_delete=models.CASCADE, verbose_name=_("Post"), related_name="notifications", null=True, blank=True ) sender = models.ForeignKey( User, on_delete=models.CASCADE, verbose_name=_("Sender"), related_name="sender", null=True, blank=True ) created_at = models.DateTimeField(_("Created_at"), auto_now_add=True) data = models.JSONField(default=dict, blank=True, null=True) class Meta: verbose_name = _("Notification") verbose_name_plural = _("Notifications")