title: Inline Custom Form in Django
body: <p>I am trying to create a system to add applications (named <code>Candidatura</code> in <code>models.py</code>) to a database and, in each application, the user can add as many experiences (named <code>CandidaturaExp</code> in <code>models.py</code>) as they wish (one to many relation).</p>
  
  <p>I already have <code>forms.py</code> and <code>views.py</code> working for the application but I have no idea how to do it so a the user can insert experiences. I also have no idea how to create a "PLUS" button in my template to add the experience form since I am not an expert in Java Script.</p>
  
  <p>So, I have the following:</p>
  
  <p>models.py</p>
  
  <pre><code>class Candidatura(models.Model):
      ## IDENTIFICACAO E  CONTACTO
      nome=models.CharField(max_length=200, verbose_name='Nome Completo')
      nacionalidade=models.CharField(max_length=200, verbose_name='Nacionalidade')
      data_nascimento=models.DateField(verbose_name='Data de Nascimento')
      residencia=models.CharField(max_length=200, verbose_name='Residência')
      localidade=models.CharField(max_length=200, verbose_name='Localidade')
      cod_postal=models.CharField(max_length=10, verbose_name='Código Postal')
      email=models.EmailField(max_length=254, verbose_name='Email')
      telefone=models.IntegerField(verbose_name='Telefone')
  
      ## HABILITACAO E CONHECIMENTOS
      nivel_academico=models.CharField(max_length=200, verbose_name='Nível Académico')
      ano_conclusao=models.CharField(max_length=4, verbose_name='Ano de Conclusão')
      curso=models.CharField(max_length=200, verbose_name='Curso')
      instituicao=models.CharField(max_length=200, verbose_name='Instituição')
      outras_hab=models.CharField(max_length=255, null=True, blank=True, verbose_name='Outras Habilitações')
      conhec_tec=models.CharField(max_length=255, null=True, blank=True, verbose_name='Conhecimentos Técnicos')
  
      ## DOCUMENTOS ANEXOS
      cv=models.FileField(upload_to=None, max_length=100, verbose_name='Curriculum Vitae', null=True, blank=True) 
      data_criado=models.DateTimeField(default=timezone.now, editable=False, verbose_name='Data de criação')
  
      def __unicode__(self):
          return self.nome
  
      ## EXPERIENCIA PROFISSIONAL
  class CandidaturaExp(models.Model):
      candidatura = models.ForeignKey(Candidatura)    
      experiencia=models.BooleanField(verbose_name='Experiência Profissional')
      ano_admissao=models.CharField(max_length=4, null=True, blank=True, verbose_name='Ano de Admissão')
      ano_saida=models.CharField(max_length=4,null=True, blank=True, verbose_name='Ano de Saída')
      empresa=models.CharField(null=True, blank=True, max_length=200, verbose_name='Empresa')
      funcao=models.CharField(null=True, blank=True, max_length=255, verbose_name='Função Desempenhada')
  
      def __unicode__(self):
          return self.candidatura
  
  class CandidaturaForm(ModelForm):
      class Meta:
          model = Candidatura
          fields = '__all__'
  
  class CandidaturaExpForm(ModelForm):
      class Meta:
          model = CandidaturaExp
          fields = '__all__'  
  </code></pre>
  
  <p>forms.py</p>
  
  <pre><code>class NovaCandidatura(forms.ModelForm):
      class Meta:
          model = Candidatura
          fields = ('__all__')
  
  class NovaCandidaturaExp(forms.ModelForm):  
      class Meta:
          model = CandidaturaExp
          fields = '__all__'
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>def inicio(request):
      return render_to_response('indexDB.html', locals(), context_instance=RequestContext(request))
  
  @login_required    
  def listing(request):
      table = CandidaturaTable(Candidatura.objects.all())
      return render(request, "listDB.html", {'table': table})
  
  @login_required
  def newform(request, template_name="NovaCandidatura.html"):
      if request.method == 'POST':
          form = NovaCandidatura(request.POST, request.FILES)
          if form.is_valid():
              form.save()
              url = urlresolvers.reverse('change_success')
              return HttpResponseRedirect(url)
      else:
          form = NovaCandidatura()
      page_title = ('Update user data')
      return render_to_response(template_name, locals(),
          context_instance=RequestContext(request))  
  </code></pre>