title: How to create a subform for Django ModelForm
body: <p>I'm having a problem to add a ManyToMany field with ModelForm, the problem is that I don't know how to create a subform to add this data to my primary form.  I want to create a subform to be saved when I click a button, and I want the data that was saved to be selected to use in the primary form.</p>
  
  <p>my model </p>
  
  <pre><code>class Teste(models.Model):
  
     name = models.CharField(max_length=255)
     parent_institution_name = models.CharField(max_length=255)
     laboratory_departament = models.CharField(max_length=255, null=True, 
     blank=True, verbose_name="Laboratório")
     cep = models.CharField(max_length=255, verbose_name="Cep")
     cnpj = models.CharField(max_length=255, verbose_name="CNPJ")
     lat = models.FloatField(blank=True, null=True)
     lng = models.FloatField(blank=True, null=True)
     institution_name = models.CharField(max_length=255, null=False, 
     verbose_name="Nome da instituição")
     parent_institution_name = models.CharField(max_length=255, blank=True, 
     null=True, verbose_name="Nome da instituição vinculada")
     coordinator = models.CharField(max_length=255, verbose_name="Pessoa 
     Responsavel")
     email = models.CharField(max_length=255, verbose_name="E-mail")
     website = models.CharField(max_length=255, blank=True, null=True, 
     verbose_name="Website")
     rad_operating_time = models.IntegerField(verbose_name="Tempo de atuação 
     ")
     research_line = models.ManyToManyField('researcher.ResearchLines')
  </code></pre>
  
  <p>my ModelForm
      class TestForm(forms.ModelForm):
          class Meta:</p>
  
  <pre><code>        model = Test
          exclude = ('employee_number', ' revenues', 'filter_grade', 'grade', ' 
          knowledge_grade',
      'application_grade', 'ie_grade', ' ia_grade', 'final_grade', 'inactive', 'last_coordinator_access', ' hr_count',
      'hr_returned', ' match_hr_count', 'general_grade', 'lat', 'lng'
      'tokens', 'iso_certification', 'other_certification', 'researchers', 'thematic_network',
      )
  
  
      widgets ={
          'name':forms.TextInput(attrs={
              'class':'form-control',
              'placeholder': 'Nome da UBC'
          }),
          'parent_institution_name': forms.TextInput(attrs={
              'class':'form-control',
              'placeholder':'Nome da Instituição à qual a UBC é vinculada'
          }),
          'laboratory_departament': forms.TextInput(attrs={
              'class':'form-control',
              'placeholder':'Laboratório/Departamento'
          }),
          'cep': forms.TextInput(attrs={
              'class':'form-control',
              'placeholder':'CEP'
          }),
          'cnpj': forms.TextInput(attrs={
              'class':'form-control',
              'placeholder':'CNPJ'
          }),
          'institution_name': forms.TextInput(attrs={
              'class':'form-control',
              'placeholder':'Nome da instituição'
          }),
          'coordinator': forms.TextInput(attrs={
              'class':'form-control',
              'placeholder':'Pessoa Responsável'
  
          }),
          'email': forms.TextInput(attrs={
              'class':'form-control',
              'placeholder':'E-mail'
          }),
          'website': forms.TextInput(attrs={
              'class':'form-control',
              'placeholder':'Website'
          }),
          'rad_operating_time': forms.TextInput(attrs={
              'class':'form-control',
              'placeholder':'Tempo de atuação em projetos de P&amp;D+I'
          }),
          'phone': forms.TextInput(attrs={
              'class':'form-control',
              'placeholder': 'Telefone'
          }),
          'partner_category': forms.RadioSelect(),
  
          'main_product':forms.CheckboxSelectMultiple( attrs={
              'type':'checkbox'
          }),        
      }
  </code></pre>
  
  <p>How my form looks, the last input shows where the subform goes to add data<br>
  <a href="https://i.stack.imgur.com/fvDnD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fvDnD.png" alt="enter image description here"></a></p>