Fixes #20157: Overwrite existing user notifications to avoid duplications (#20167)

This commit is contained in:
Jeremy Stretch 2025-08-22 19:13:24 -04:00 committed by GitHub
parent 66140fc017
commit 7033230388
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -173,14 +173,17 @@ class NotificationGroup(ChangeLoggedModel):
User.objects.filter(groups__in=self.groups.all())
).order_by('username')
def notify(self, **kwargs):
def notify(self, object_type, object_id, **kwargs):
"""
Bulk-create Notifications for all members of this group.
"""
Notification.objects.bulk_create([
Notification(user=member, **kwargs)
for member in self.members
])
for user in self.members:
Notification.objects.update_or_create(
object_type=object_type,
object_id=object_id,
user=user,
defaults=kwargs
)
notify.alters_data = True