Hello,
I have the following multi-table inheritance situation:
from django.db import Models
class Partner(models.Model):
# this model contains common data for companies and persons
code = models.CharField()
name = models.CharField()
class Person(Partner):
# some person-specific data
ssn = models.CharField()
class Company(Partner):
# some company-specific data
tax_no = models.CharField()
How can I convert a Company instance to a Person one, and vice-versa?
Let's say someone mistakenly created a Company instance with person's details:
company = Company(name="John Smith", tax_no="<some-ssn-#>")
I want to convert all wrong Company objects (that were meant to be Persons) to Person objects, keeping all related records (I have models with FKs to the Partner model, so it's important to keep the same partner_ptr value). I can do something like this:
person = Person(name=company.name, ssn=company.tax_no, partner_ptr=company.partner_ptr)
So far so good, but is it possible to delete the Company objects that are not needed anymore? Deleting the Company object will also delete it's parent Partner object (and any related to the partner, including the newly created Person object).
Any recommendations? Thanks!
P.S.: This is an already deployed system, with lots of data in it and it is not possible to redesign the whole Partner-Person-Company inheritance concept.