mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-15 20:56:34 +00:00
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
''' alert a user to activity '''
|
|
from django.db import models
|
|
from .base_model import BookWyrmModel
|
|
|
|
|
|
NotificationType = models.TextChoices(
|
|
'NotificationType',
|
|
'FAVORITE REPLY MENTION TAG FOLLOW FOLLOW_REQUEST BOOST IMPORT')
|
|
|
|
class Notification(BookWyrmModel):
|
|
''' you've been tagged, liked, followed, etc '''
|
|
user = models.ForeignKey('User', on_delete=models.PROTECT)
|
|
related_book = models.ForeignKey(
|
|
'Edition', on_delete=models.PROTECT, null=True)
|
|
related_user = models.ForeignKey(
|
|
'User',
|
|
on_delete=models.PROTECT, null=True, related_name='related_user')
|
|
related_status = models.ForeignKey(
|
|
'Status', on_delete=models.PROTECT, null=True)
|
|
related_import = models.ForeignKey(
|
|
'ImportJob', on_delete=models.PROTECT, null=True)
|
|
read = models.BooleanField(default=False)
|
|
notification_type = models.CharField(
|
|
max_length=255, choices=NotificationType.choices)
|
|
|
|
class Meta:
|
|
''' checks if notifcation is in enum list for valid types '''
|
|
constraints = [
|
|
models.CheckConstraint(
|
|
check=models.Q(notification_type__in=NotificationType.values),
|
|
name="notification_type_valid",
|
|
)
|
|
]
|