def add_idea(request): """ This is a view to add an idea. Note that this duplicates functionality in the admin pages, however this view, unlike the administration site, can have restricted access by user, which I will be adding eventually. """ if request.method == 'POST': # Bind the post request to the previously defined IdeaForm form = IdeaForm(request.POST) if form.is_valid(): # Since IdeaForm is a ModelForm, we can save to the database directly if the form # validated. form.save() # After saving, redirect back to the main page return HttpResponseRedirect('/madscientist/') else: # Otherwise, display a blank version of the form form = IdeaForm() context = {'form': form } return render_to_response('madscientist/add_idea.html', context_instance=RequestContext(request, context))