title: How to save an Inline Formset inside another?
body: <p>I have the following situation:
  I have to create a project, and inside this project I can have multiple internships and for each internship I can have multiple interns. I was able to create and save the Internship, but I can't find a way to create the interns. Is there a way to do so?</p>
  <p>Here's my code:</p>
  <p>view.py</p>
  <pre><code>def cadastrar_bolsa(request, projeto_id):
  if request.method == 'GET':
      projeto_editar = Projeto.objects.filter(id=projeto_id).first()
      if projeto_editar is None:
          return redirect(reverse('projeto'))
      form = EditForm(instance=projeto_editar)
  
      form_bolsa_factory = inlineformset_factory(Projeto, Bolsa, form=BolsaForm, extra=1)
      form_bolsa = form_bolsa_factory(instance=projeto_editar)
  
      form_bolsista_factory = inlineformset_factory(Bolsa, Bolsista, form=BolsistaForm, extra=1)
      form_bolsista = form_bolsista_factory(instance=????)
  
      context = {
          'form': form,
          'form_bolsa': form_bolsa,
          'form_bolsista': form_bolsista,
          'id': projeto_id,
      }
      return render(request, 'cadastrar_bolsa.html', context)
  elif request.method == 'POST':
      projeto_editar = Projeto.objects.filter(id=projeto_id).first()
      if projeto_editar is None:
          return redirect(reverse('projeto'))
      form = EditForm(request.POST, instance=projeto_editar)
  
      form_bolsa_factory = inlineformset_factory(Projeto, Bolsa, form=BolsaForm, extra=1)
      form_bolsa = form_bolsa_factory(request.POST, instance=projeto_editar)
  
      form_bolsista_factory = inlineformset_factory(Bolsa, Bolsista, form=BolsistaForm, extra=1)
      form_bolsista = form_bolsista_factory(instance=????)
  
      if form.is_valid() and form_bolsa.is_valid():
          projeto_editado = form.save()
          form_bolsa.instance = projeto_editado
          form_bolsa.save()
          ?????
          return redirect('bolsas', projeto_id)
      else:
          context = {
              'form': form,
              'form_bolsa': form_bolsa,
              'form_bolsista': form_bolsista,
              'id': projeto_id,
          }
          return render(request, 'cadastrar_bolsa.html', context)
  </code></pre>
  <p>models.py</p>
  <pre><code>class Projeto(models.Model):
  
      nome_projeto = models.CharField('Nome do Projeto', max_length=200)
      data_de_inicio = models.DateField('Data de Inicio')
      data_de_fim = models.DateField('Data de Termino')
      objetivo_projeto = models.TextField('Objetivo do Projeto', max_length=800)
  
      def __str__(self):
          return self.nome_projeto
  
  class Bolsa(models.Model):
      projeto = models.ForeignKey(Projeto, on_delete=models.CASCADE, related_name='bolsas')
      orgao_remunerador = models.CharField(max_length=50, blank=True)
  
      def __str__(self):
          return self.orgao_remunerador
  
  
  class Bolsista(models.Model):
      bolsa = models.ForeignKey(Bolsa, on_delete=models.CASCADE, related_name='bolsistas')
      bolsista = models.CharField('Nome', max_length=200, blank=True)
      email = models.EmailField(max_length=200, blank=True)
  
      def __str__(self):
          return self.bolsista
  </code></pre>
  <p>forms.py</p>
  <pre><code>    class EditForm(forms.ModelForm):
      format_key = 'DATE_INPUT_FORMATS'
  
      class Meta:
          model = Projeto
          fields = '__all__'
  
      nome_projeto = forms.CharField(label='Nome do Projeto:', required=True, widget=forms.TextInput(
          attrs={
              'class': 'form-control col-8',
              'maxlength': '200',
          }
      ))
  
      data_de_inicio = forms.DateField(label='Data de Inicio:', required=True, widget=forms.DateInput(
          attrs={
              'type': 'date',
              'date-input': 'date',
              'class': 'form-control col-4',
              'format': '%d-%m-%Y',
              'value': '{{data_de_inicio|date:&quot;d-m-Y&quot;}}'
          }
      ))
  
      data_de_fim = forms.DateField(label='Data de Término:', required=True, widget=forms.DateInput(
          attrs={
              'type': 'date',
              'class': 'form-control col-4',
              'format': '%d-%m-%Y'
          }
      ))
  
      objetivo_projeto = forms.CharField(label='Objetivos do Projeto:', required=True, widget=forms.Textarea(
          attrs={
              'type': 'text',
              'class': 'form-control col-8',
              'maxlength': '800'
          }
      ))
  
  class BolsistaForm(forms.ModelForm):
      class Meta:
          model = Bolsista
          fields = '__all__'
  
      bolsista = forms.CharField(label=&quot;Bolsista do Projeto&quot;, widget=forms.TextInput(
          attrs={
              'class': 'form-control col-7',
              'maxlength': '200',
          }
      ))
  
      email = forms.EmailField(label='E-mail', required=True, widget=forms.EmailInput(
          attrs={
              'class': 'form-control col-7',
              'maxlength': '200',
              'placeholder': &quot;Ex.: jose@unemat.br&quot;,
              'name': 'email'
          }
      ))
  
  
  class BolsaForm(forms.ModelForm):
      class Meta:
          model = Bolsa
          fields = '__all__'
  
      orgao_remunerador = forms.CharField(label=&quot;Qual o orgão remunerador?&quot;, widget=forms.TextInput(
          attrs={
              'class': 'form-control col-8',
              'maxlength': '200',
          }
      ))
  </code></pre>
  <p>I've put question marks on the part I couldn't find a way to solve.</p>