I'm not sure if I understand your problem correctly. If you want to display all Pets
that belong to the Person
:
def show_pets(request, person_id=None):
person = get_object_or_404(Person.objects.select_related(), id=person_id)
if request.method == 'POST':
person_form = PersonForm(request.POST, instance=person)
pet_formset = PetFormSet(request.POST, instance=person)
# Rest of your code here
else:
person_form = PersonForm(instance=person)
pet_formset = PetFormSet(instance=person)
return render_to_response('your_template.html', {'person_form': person_form,
'pet_formset': pet_formset)})
Then you just need to render both forms in your template and add add
and delete
functionality