def add_project(request): # Get the context from the request. context = RequestContext(request) # A HTTP POST? if request.method == 'POST': form = ProjectForm(request.POST) # Have we been provided with a valid form? if form.is_valid(): # Save the new projecto to the database. form.save(commit=True) # Now call the index() view. # The user will be shown the homepage. return redirect('project_list') else: # The supplied form contained errors - just print them to the terminal. print form.errors else: # If the request was not a POST, display the form to enter details. form = ProjectForm() # Bad form (or form details), no form supplied... # Render the form with error messages (if any). # return render_to_response('unit/add_project.html', {'form': form}, context) #return render_to_response('unit/add_project.html', {'form': form}, context) return render(request, 'unit/add_project.html', {'form': form})
def edit_project(request, id): project = get_object_or_404(Project, id=id) form = ProjectForm(request.POST or None, instance=project) if form.is_valid(): form.save() return redirect('project_list') #return HttpResponseRedirect(reverse('edit_project', project)) return render(request, 'unit/add_project.html', {'form': form})