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 ###