How do I create a copy of a Django model instance along with a related One-to-One field?
Copying the model instance works fine, but when I try to create a copy of the one-to-one model, all the fields of that model become blank. Here's what I did:
new_address = self.object.designer.address # type Address
new_address.pk = None
new_address.save()
new_contact = self.object.designer # type Contact
new_contact.pk = None
new_contact.address = new_address
new_contact.save()
self.object.shippinginfo.contact = new_contact
self.object.shippinginfo.save()
The Contact model has a one-to-one relationship with the Address model. I tried printing out the values, after creating the new address, the values were correct when I printed them out, but then when I save the address to the address field of the new contact, all of the fields of the address are blank except the pk...