...
The database model schema for a notification
Code Block | ||
---|---|---|
| ||
class NotificationApplication(models.TextChoices): |
...
DISCUSSION = 'DISCUSSION' |
...
class NotificationTypes(models.TextChoices): |
...
NEW_POST = 'NEW_POST', |
...
NEW_RESPONSE = 'NEW_RESPONSE' |
...
class NotificationTypeContent(models.TextChoices): |
...
NEW_POST: 'You have received a new response on your post {response_text}' |
...
class Notification(TimeStampedModel): |
...
app_name = models.CharField(max_length=64, choices=NotificationApplication.choices) |
...
notification_type = models.CharField(max_length=64, choices=NotificationTypes.choices) |
...
# e.g "You have received a new response on your post {response_text}" |
...
# this content will be rendered with the given context and also translated |
...
content = models.CharField(max_length=1024, choices=NotificationTypeContent.choices) |
...
# e.g {"response_text": "This is a response"} |
...
content_context = models.JSONField(default={}) |
...
# This is the url that the user will be redirected to when clicking on the notification [Optional] |
...
content_url = models.CharField(max_length=1024, null=True, blank=True) |
...
# the user foreign key will be indexed |
...
user = models.ForeignKey(User, related_name="notifications", on_delete=models.CASCADE) |
...
read = models.BooleanField(default=False) |
...
seen = models.BooleanField(default=False) |
app_name (Char Field, char_limit: 64): This is the application/service that generated the notification e.g “DISCUSSION”. Keeping this in a separate field will make it possible to quickly filter out app specific notifications. This is a potential field to be indexed as well but I have kept this as non indexed for now as the user field is already indexed and the most likely query is on a per user basis.
...