1👍
✅
If you have a normal parent-child models you will get attribute in child to access parent. You can update this attribute with new parent object.
Also, the way you create parent object may not work, you need to call method on that object.
So I will update child’s copy()
method as:
class B(A):
def copy(self):
# this method is what I am confused about
new_parent = self.a.copy() # change 'a' with appropriate attribute name
obj = self
obj.pk = None
# set obj's parent model to 'new_parent'
obj.a = new_parent
obj.save()
return obj
Source:stackexchange.com