Skip to content

Commit e76385d

Browse files
committed
Actually save the m2m on the destination.
1 parent 335a9c5 commit e76385d

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
@@ -719,6 +719,8 @@ def __duplicate_linked_m2m_fields(self, duplicate):
719719
:return: The duplicate instance objects from all the many-to-many fields duplicated.
720720
"""
721721

722+
changed = False
723+
722724
for field in self._meta.many_to_many:
723725
if all(
724726
[
@@ -730,5 +732,9 @@ def __duplicate_linked_m2m_fields(self, duplicate):
730732
source = getattr(self, field.attname)
731733
destination = getattr(duplicate, field.attname)
732734
destination.set(list(source.all()))
735+
changed = True
736+
737+
if changed:
738+
duplicate.save()
733739

734740
return duplicate

0 commit comments

Comments
 (0)