You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a question about the way Notification are created in the handler in the case of multiple recipients. It seems that they are not created in bulk. Would it be possible to change the following code?
for recipient in recipients:
newnotify = Notification(
recipient=recipient,
actor_content_type=ContentType.objects.get_for_model(actor),
actor_object_id=actor.pk,
verb=str(verb),
public=public,
description=description,
timestamp=timestamp,
level=level,
)
# Set optional objects
for obj, opt in optional_objs:
if obj is not None:
setattr(newnotify, '%s_object_id' % opt, obj.pk)
setattr(newnotify, '%s_content_type' % opt,
ContentType.objects.get_for_model(obj))
if kwargs and EXTRA_DATA:
newnotify.data = kwargs.copy()
newnotify.save()
to something like that:
notifications = []
for recipient in recipients:
newnotify = Notification(
recipient=recipient,
actor_content_type=ContentType.objects.get_for_model(actor),
actor_object_id=actor.pk,
verb=str(verb),
public=public,
description=description,
timestamp=timestamp,
level=level,
)
# Set optional objects
for obj, opt in optional_objs:
if obj is not None:
setattr(newnotify, '%s_object_id' % opt, obj.pk)
setattr(newnotify, '%s_content_type' % opt,
ContentType.objects.get_for_model(obj))
if kwargs and EXTRA_DATA:
newnotify.data = kwargs.copy()
notifications.append(newnotify)
Notification.objects.bulk_create(notifications)
The text was updated successfully, but these errors were encountered:
Hello,
I have a question about the way Notification are created in the handler in the case of multiple recipients. It seems that they are not created in bulk. Would it be possible to change the following code?
to something like that:
The text was updated successfully, but these errors were encountered: