def edit(request, id): instance = get_object_or_404(Item, id=id) form = ItemForm(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(request): if request.method == 'POST': form = ItemForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/add/') # Redirect after POST else: form = ItemForm() # An unbound form return render(request, 'inv_app/additem.html', { 'form': form, })