2

I am trying to copy an object that extends another object through multi table inheritance.

The parent is Group and the child is Location

The problem is that the parent object is changed instead of creating a new parent and child object.

Here is what I am doing:

location = get_object_or_404(Location, pk=pk)

        location.pk = None
        location.name = location.name+' - child object'
        location.save()

Instead of creating a new location and group row in their respective tables, this updates the group table to have the name = name + ' - child object'.

how can I have this process create a new location and group row instead of updating the Group row?

Thanks!

1 Answer 1

4

The key here is that multi-table inheritance in Django is implemented using foreign keys, so an object that "inherits" another model is simply ForeignKey'ed to that other model. You'll need to duplicate both.

For how to do so, check out the solution in this answer.

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.