Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1077679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:36:39+00:00 2026-05-16T21:36:39+00:00

I have the following multi-table inheritance situation: from django.db import Models class Partner(models.Model): #

  • 0

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.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:36:40+00:00Added an answer on May 16, 2026 at 9:36 pm

    One way to go about this would be to first add a dummy Partner per each company awaiting deletion. After that you can update the partner_ptr of all unwanted Company instances to the appropriate dummy partner instance. Finally you can delete all the companies.

    Of course you can use South to help do this.

    Update

    Did some rudimentary testing and this works. I am using Django 1.2.1.

    I have tried this, it’s not possible: In 1: Company.objects.get(pk=7924) Out1: In [2]: c.partner_ptr = Partner() In [3]: c.pk In [4]: c.delete() AssertionError: Company object can’t be deleted because its partner_ptr_id attribute is set to None. Setting the partner_ptr instance to a dummy one changes the company’s PK and it’s not the Company.

    You have to attach a new Partner and then save the company. Then you can safely delete it.

    So:

    company = Company.objects.get(pk=7924)
    dummy_partner = Partner(code = "dummy", name = "dummy")
    company.partner_ptr = dummy_partner
    company.save()
    company.delete()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Django Model Inheritance query a central table Following along the officail docs
I have this query which involves a table from another server: select count(serialno), max(convert(varchar(10),Crtd_DateTime,101))
I have a rails app that requires multi-table inheritance for which I am using
For example, I am using multi-table inheritance for a class Node with sub-classes ConceptNode
In my Rails app I have a multi-level hierarchy of the following kind: class
Lets say I have following query: SELECT * FROM table WHERE id = 1
I have the following multi-select box in a HTML form, where user can select
I have got a the following problem: I have got multi-step form where in
I have a multi-table SQL query. My need is: The query should I generate
I have following trigger written for my application which gives me this error Msg

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.