I want to make several contact records, I wanted them to be more dynamic, for example, the person has a number of phones or cell phones or email's and while on the site, he can click on a sum sign and the page presents new boxes to enter this data and then, you would need to register all this information in the database. How can I do it?
insert.html
<div class='col-sm-12 padding-top-3'>
<legend>Outros Contatos</legend>
<table class='table table-hover table-bordered'>
<tr>
<th class='text-center'>Telefone</th>
<th class='text-center'>Celular</th>
<th class='text-center'>E-mail</th>
<th class='text-center'></th>
</tr>
<tr>
<td class='text-center'>{{ formCont.tel }}</th>
<td class='text-center'>{{ formCont.cel }}</th>
<td class='text-center'>{{ formCont.email }}</th>
<th class='text-center'> + </th>
<tr>
<table>
</div>
models.py:
class RegisterContact(models.Model):
tel = models.CharField('Telefone', max_length = 15, blank=True, null=True)
cel = models.CharField('Celular', max_length = 20, blank=True, null=True)
email = models.EmailField('Email', blank=True, null=True)
ref_pes = models.OneToOneField(Pessoa)
def __str__(self):
return self.tel
class Meta:
verbose_name = 'Contato'
verbose_name_plural = 'Contatos'
views.py:
def insert(request):
form = PessoaForm(request.POST or None)
formCont = RegisterContactForm(request.POST or None)
if form.is_valid():
resp = form.save()
formCont.save(resp.id)
return redirect('accounts:home')
template_name = 'accounts/insert.html'
context = {
'form': form,
'formCont': formCont,
}
return render(request, template_name, context)