def edit_person(request, id): instance = get_object_or_404(Person, id=id) form = PersonForm(request.POST or None, instance=instance) if form.is_valid(): form.save() return HttpResponseRedirect('/') return render(request, 'inv_app/additem.html', {'form': form})
def add_person(request): if request.method == 'POST': person_form = PersonForm(request.POST) if person_form.is_valid(): person_form.save() return HttpResponseRedirect('') # Redirect after POST else: person_form = PersonForm() # An unbound form return render(request, 'inv_app/additem.html', { 'form': person_form, })