Search code examples
djangoadminmodelsmultiple-inheritance

Django admin with multiple heritage


I have the following class

class master(models.Model):
    topic = models.ManyToManyField('Topic')

class child1(master):
    question = models.CharField(max_length=100, null=False)

class child2(master):
    answer_display = models.CharField(max_length=300, null=False)

In the django admin, I wish add an object child1 and at the same time an object child2 that have the same ID given by the parrent model.

How I'm supposed to do that ?

Edit: If I create an object child1 and an object child2, i don't have the same master ID as i wish


Solution

  • It wasn't a good way to organised my models

    I change It for something like that

    class master(models.Model):
        topic = models.ManyToManyField('Topic')
    
    class child1(child2):
        question = models.CharField(max_length=100, null=False)
    
    class child2(master):
        answer_display = models.CharField(max_length=300, null=False)