Adds notifications

Fixes #70
This commit is contained in:
Mouse Reeve
2020-03-07 14:50:29 -08:00
parent 95c8dc1d67
commit f4008eb8c8
13 changed files with 176 additions and 5 deletions

View File

@ -1,5 +1,5 @@
''' bring all the models into the app namespace '''
from .book import Book, Work, Edition, Author
from .shelf import Shelf, ShelfBook
from .status import Status, Review, Favorite, Tag
from .status import Status, Review, Favorite, Tag, Notification
from .user import User, UserRelationship, FederatedServer

View File

@ -76,3 +76,29 @@ class Tag(FedireadsModel):
class Meta:
unique_together = ('user', 'book', 'name')
class Notification(FedireadsModel):
''' you've been tagged, liked, followed, etc '''
user = models.ForeignKey('User', on_delete=models.PROTECT)
related_book = models.ForeignKey(
'Book', 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)
read = models.BooleanField(default=False)
notification_type = models.CharField(max_length=255)
def save(self, *args, **kwargs):
# TODO: there's probably a real way to do enums
types = [
'FAVORITE',
'REPLY',
'TAG',
'FOLLOW'
]
if not self.notification_type in types:
raise ValueError('Invalid notitication type')
super().save(*args, **kwargs)