Django multi-table inheritance with separate (identical) tables without pointers

advertisements

FIRST POST/QUESTION :) Hope you guys can help...

I'm subclassing an existing model (from another application entirely) and want my model to have it's own database table. A identical clone/replica of the original table not just a table with a pointer to the data stored in the "parent" table.

Here's my model:

class A (models.Model):
    name = models.CharField('name')

class MyA (A):
    class Meta:
        db_table = 'My_A'

Here's my db tables:

CREATE TABLE A
(
  id serial NOT NULL,
  "name" character varying(50) NOT NULL,
  ...
)

CREATE TABLE My_A
(
  A_ptr_id integer NOT NULL,
  ...
)

AND Here's what I would like to have:

CREATE TABLE A
(
  id serial NOT NULL,
  "name" character varying(50) NOT NULL,
  ...
)

CREATE TABLE My_A
(
  id serial NOT NULL,
  "name" character varying(50) NOT NULL,
  ...
)

Edit:

FYI: Ended up copy-pasting the 3rd party model


When you inherit a Django Model it will always generate an implict 1-1 relation to the parent model. And Django will only generate the fields for your inherited model. Which in general makes total sense to me. But for your use case is cumbersome. Since we are taling about Django core functionality, it might be hard to workaround. You could try to copy and paste your 3rd party model into your code as a proxy model and inherit from there.

Update: But why do you want to separate the data into different tables? What is the final objective?