Create notification when adding or suggesting a book to a list

This commit is contained in:
Mouse Reeve
2021-02-10 13:46:56 -08:00
parent 2bf4b17113
commit 8842db3c1b
3 changed files with 48 additions and 26 deletions

View File

@ -1,4 +1,5 @@
''' make a list of books!! '''
from django.apps import apps
from django.db import models
from bookwyrm import activitypub
@ -71,6 +72,22 @@ class ListItem(CollectionItemMixin, BookWyrmModel):
object_field = 'book'
collection_field = 'book_list'
def save(self, *args, **kwargs):
''' create a notification too '''
created = not bool(self.id)
super().save(*args, **kwargs)
list_owner = self.book_list.user
# create a notification if somoene ELSE added to a local user's list
if created and list_owner.local and list_owner != self.user:
model = apps.get_model('bookwyrm.Notification', require_ready=True)
model.objects.create(
user=list_owner,
related_user=self.user,
related_list_item=self,
notification_type='ADD',
)
class Meta:
''' an opinionated constraint! you can't put a book on a list twice '''
unique_together = ('book', 'book_list')