def person_view(request, person_id=None): if person_id == None: person = Person() else: person = Person.objects.get(id = person_id) PhoneFormSet = inlineformset_factory(Person, Phone, can_delete=True) AddressFormSet = inlineformset_factory(Person, Address, can_delete=True) if request.method == "POST": personform = PersonForm(request.POST, instance=person) phoneformset = PhoneFormSet(request.POST, request.FILES, instance=person, prefix='phone') addressformset = AddressFormSet(request.POST, request.FILES, instance=person, prefix='address') if personform.is_valid() and phoneformset.is_valid() and addressformset.is_valid(): personform.save() phoneformset.save() addressformset.save() if '_save' in request.POST: return HttpResponseRedirect('/admin/person/person/') if '_addanother' in request.POST: return HttpResponseRedirect('/admin/person/person/add/') else: personform = PersonForm(instance=person) phoneformset = PhoneFormSet(instance=person, prefix='phone') addressformset = AddressFormSet(instance=person, prefix='address') return render_to_response('person.html', { 'personform' : personform, 'phoneformset' : phoneformset, 'addressformset' : addressformset, }) ### Template for this view ###
{% for field in personform %}
{{ field.errors }} {{ field.label_tag }}: {{ field }}
{% endfor %}

Phone Numbers

{% for field in phoneformset.forms.0 %} {% if not field.is_hidden %} {% endif %} {% endfor %} {% for f in phoneformset.management_form %} {{ f }} {% endfor %} {% for f in phoneformset.forms %} {% for field in f %} {% if not field.is_hidden %} {% else %}
{{ field.label }}
{{ field.errors }} {{ field }} {{ field }} {% endfor %}

Addresses

{% for field in addressformset.forms.0 %} {% if not field.is_hidden %} {% endif %} {% endfor %} {% for f in addressformset.management_form %} {{ f }} {% endfor %} {% for f in addressformset.forms %} {% for field in f %} {% if not field.is_hidden %} {% else %}
{{ field.label }}
{{ field.errors }} {{ field }} {{ field }} {% endfor %}