Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion onyx/data/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Any
from django.db import transaction, DatabaseError, models
from rest_framework import serializers, exceptions
from simple_history.utils import bulk_create_with_history
from accounts.models import User
from utils.defaults import CurrentUserSiteDefault, CurrentProjectDefault
from utils.fieldserializers import (
Expand Down Expand Up @@ -707,9 +708,22 @@ def _save(
# Save any nested objects, providing a link to the current instance
for node in self.nodes.values():
if isinstance(node, list):
instances = []
for n in node:
if n:
n._save(link=instance)
if n.serializer.instance:
n._save(link=instance)
else:
instances.append(
n.serializer.Meta.model(
**(n.serializer.validated_data | {"link": instance})
)
)
Comment thread
tombch marked this conversation as resolved.
if instances:
Comment thread
tombch marked this conversation as resolved.
serializer_model = node[0].serializer.Meta.model
bulk_create_with_history(
instances, serializer_model, batch_size=100
)
Comment thread
tombch marked this conversation as resolved.
Comment thread
tombch marked this conversation as resolved.
Comment thread
tombch marked this conversation as resolved.
else:
node._save(link=instance)

Expand Down