Skip to content

Commit 4f474fc

Browse files
committed
Fixes #20157: Overwrite existing user notifications to avoid duplications
1 parent d5e49c8 commit 4f474fc

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

netbox/extras/models/notifications.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,17 @@ def members(self):
173173
User.objects.filter(groups__in=self.groups.all())
174174
).order_by('username')
175175

176-
def notify(self, **kwargs):
176+
def notify(self, object_type, object_id, **kwargs):
177177
"""
178178
Bulk-create Notifications for all members of this group.
179179
"""
180-
Notification.objects.bulk_create([
181-
Notification(user=member, **kwargs)
182-
for member in self.members
183-
])
180+
for user in self.members:
181+
Notification.objects.update_or_create(
182+
object_type=object_type,
183+
object_id=object_id,
184+
user=user,
185+
defaults=kwargs
186+
)
184187
notify.alters_data = True
185188

186189

0 commit comments

Comments
 (0)