Skip to content

Commit ebdd083

Browse files
pcraciunoiujackton1
authored andcommitted
Actually save the m2m on the destination.
1 parent 99111f8 commit ebdd083

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

model_clone/mixin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@ def __duplicate_linked_m2m_fields(self, duplicate):
718718
:return: The duplicate instance objects from all the many-to-many fields duplicated.
719719
"""
720720

721+
changed = False
722+
721723
for field in self._meta.many_to_many:
722724
if all(
723725
[
@@ -729,5 +731,9 @@ def __duplicate_linked_m2m_fields(self, duplicate):
729731
source = getattr(self, field.attname)
730732
destination = getattr(duplicate, field.attname)
731733
destination.set(list(source.all()))
734+
changed = True
735+
736+
if changed:
737+
duplicate.save()
732738

733739
return duplicate

0 commit comments

Comments
 (0)