1
0
Fork 0

Deduplicate notifications in notification model

This commit is contained in:
Mouse Reeve 2021-02-10 16:21:29 -08:00
parent d9e65aa363
commit e0cfb009e4
5 changed files with 16 additions and 12 deletions

View file

@ -25,6 +25,21 @@ class Notification(BookWyrmModel):
notification_type = models.CharField(
max_length=255, choices=NotificationType.choices)
def save(self, *args, **kwargs):
''' save, but don't make dupes '''
# there's probably a better way to do this
if self.__class__.objects.filter(
user=self.user,
related_book=self.related_book,
related_user=self.related_user,
related_status=self.related_status,
related_import=self.related_import,
related_list_item=self.related_list_item,
notification_type=self.notification_type,
).exists():
return
super().save(*args, **kwargs)
class Meta:
''' checks if notifcation is in enum list for valid types '''
constraints = [