0

I have two object A and B with same type, and want to copy all object A's field to object B but keep object B's PK.

A well known method is change object A's pk to None and save, it will create a new object with object A's field, but what I want is to copy to an existing object not create a new object.

1
  • It depends on what A contains. If it's simple enough you can use the copy module, but it's difficult to suggest anything without some more context. Commented Sep 7, 2015 at 0:29

1 Answer 1

2

Just copy the PK and save.

objA.pk = objB.pk
objA.save()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.