Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODELS:
- class Pais(models.Model):
- nome = models.CharField('Nome', max_length=50)
- class Brinq(models.Model):
- descricao = models.CharField('Nome', max_length=50)
- class Filhos(models.Model):
- nome = models.CharField('Nome', max_length=50)
- idade = models.IntegerField('Idade')
- pai = models.ForeignKey('Pais')
- brinq = models.ForeignKey('Brinq', related_name='Brinq')
- VIEW:
- def editPai(request, idpai=None):
- if idpai:
- pai = Pais.objects.get(id=idpai)
- else:
- pai = None
- ItensInlineFormSet = inlineformset_factory(Pais, Filhos, form=FilhosForm, extra=1)
- formPais = PaisForm()
- formsetItens = ItensInlineFormSet(instance=pai)
- return render_to_response("base.html", {
- "formPais": formPais, "formsetItens": formsetItens
- }, context_instance=RequestContext(request), )
- FORM:
- class PaisForm(ModelForm):
- class Meta:
- model = Pais
- class FilhosForm(ModelForm):
- class Meta:
- model = Filhos
- and simple HTML:
- {{ formPais }}
- <table>
- {% for form in formsetItens %}
- <tr>
- <td> {{ form.nome }}</td>
- <td> {{ form.idade }}</td>
- <td> {{ form.brinq__descricao }}</td>
- </tr>
- {% endfor %}
- </table>
Advertisement
Add Comment
Please, Sign In to add comment