How to save a pop up form (modal form) (field) having many-to-many relationship in Django?

I have got two models as shown in models.py. How well can it be done so that when creating a new object in the parent model it allows the data entry user to create one or more objects in the child model and link it to the parent model object using one form?

models.py

class ChildModel(models.Model):
    field = models.CharField()

class ParentModel(models.Model):
    child = ManyToManyField(ChildModel)

Case Example

Let's have a parent and Children belonging to a parent. That is when creating a new parent you can attach his or her children's details.

What I have tried

I have joined both models using the many-to-many Django relationship. To attach the children to a parent, the first thing you need to do is create the children first, in a separate form, then select them from a list while creating the parent.

Complains

Is tiresome and not good when handling large data, for example, if there are 1000 children and you need to attach them to their respective parents.

Project Screenshots

parent creation form

Parent creation form showing field to select children

child creation form

Child creation form

My Expectations

The following image illustrates how a pop-up is generated when the green plus sign is clicked, a pop-up window appears having a child creation form when the form is saved, child is added to the list

Children creation form in the Django super admin dashboard

Back to Top