I use Django and I have some objects with ManyToManyFields. I'd like to duplicate these objects. I've found 'deepcopy' which works almost perfectly.
>>> e = Equipement.objects.get(pk=568)
>>> ee = deepcopy(e)
>>> ee.connexion.all()
[<Connexion: COMETE - Proxyweb>]
>>> ee.id=None
>>> ee.save()
>>> ee.connexion.all()
[]
I don't want to loose the ManyToMany information when I save. Do you know a trick in order to do that quickly in Django ?
Thanks.
Just add them using the old object:
ee = deepcopy(e)
ee.id=None
ee.save()
ee.connexion.add(*e.connexion.all())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With