Skip to content

Commit

Permalink
add modification for many-to-many fields with though argument in `upd…
Browse files Browse the repository at this point in the history
…ate_or_create_reverse_relations` method
  • Loading branch information
qzibet committed Jun 12, 2023
1 parent 1b25692 commit 48f0ffe
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drf_writable_nested/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ def update_or_create_reverse_relations(self, instance, reverse_relations):
)
elif not related_field.many_to_many:
save_kwargs[related_field.name] = instance
elif related_field.many_to_many and related_field.remote_field.through:
save_kwargs['parent_instance'] = instance

new_related_instances = []
errors = []
Expand Down Expand Up @@ -209,6 +211,7 @@ def update_or_create_direct_relations(self, attrs, relations):
for field_name, (field, field_source) in relations.items():
obj = None
data = self.get_initial()[field_name]

model_class = field.Meta.model
pk = self._get_related_pk(data, model_class)
if pk:
Expand All @@ -217,7 +220,7 @@ def update_or_create_direct_relations(self, attrs, relations):
).first()
else:
if getattr(field, 'only_assignation_allowed', False):
return
continue
serializer = self._get_serializer_for_field(
field,
instance=obj,
Expand Down

0 comments on commit 48f0ffe

Please sign in to comment.