0

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

remy_dev
  • 195
  • 1
  • 12

2 Answers2

0

I'm a bit confused as to what you want, but if you want to link the 2 "childs" to a "parent", you could create a ForeignKey field on both of the childs and use that to link to a "parent" model.

Also if you want your child1 and child2 models to inherit from the master model, it must have abstract = True in its class Meta.

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

    class Meta:
        abstract = True

class child1(master):
    question = models.CharField(max_length=100, null=False)
sham
  • 1,214
  • 10
  • 16
  • I don't want change my current model, it's works. But I wish add contents with the django admin, ans i don't understand how i'm supposed to write my admin.py Because i wish add content to both child in the same time – remy_dev Aug 31 '17 at 10:38
0

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)
remy_dev
  • 195
  • 1
  • 12