I have some Django models with a structure similar to this:
class Grandparent(models.Model):
name = models.CharField(max_length=80)
class Parent(models.Model):
name = models.CharField(max_length=80)
grandparent = models.ForeignKey(Grandparent, related_name='children')
class Child(models.Model):
parent = models.ForeignKey(Parent, related_name='children')
class ChildA(Child)
something = models.CharField(max_length=80)
anotherthing = models.IntegerField()
class ChildB(Child)
anything = models.CharField(max_length=80)
hello = models.BooleanField()
So basically, there are two kind of children which inherit from a practically abstract Child model. (It is not really abstract so I could use a foreign key with it).
The question is – how will I be able to create a link from the admin page of the first model (Grandparent) to the creation page of a new Parent model?
That Parent model needs to already have the Grandparent foreign key field populated by the currently viewed grandparent page id.
Inlines are the thing that comes to mind, but I will not be able to use them because inlines cannot be nested and I will be needing them to manipulate the fields inside ChildA and ChildB on the Parent page.
The answer consists of two steps: