0
I want to do multiple contact records, I wanted it to be more dynamic, for example, the person has a number of phones or cell phones or emails and while on the site, she can click on a summation sign and the page presents new text boxes to enter this data and then, she would need to register all this information in the database. How can I do?
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>
py.models:
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'
py views.:
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)
Please arrange the indentation of your Python code. Paste the code here and use the button
{}
to format - you are just indenting the first line, and making your languages invalid code in the process.– jsbueno
Search By Formsetfactory. This will suit you if you haven’t solved the problem after so long.
– Erico Oliveira