Skip to content

Instantly share code, notes, and snippets.

@teethgrinder
Last active June 23, 2016 16:27
Show Gist options
  • Save teethgrinder/ab693a92ce6afd5885f0427423a7178f to your computer and use it in GitHub Desktop.
Save teethgrinder/ab693a92ce6afd5885f0427423a7178f to your computer and use it in GitHub Desktop.
def add_project(request):
form = ProjectForm()
if request.method == 'POST':
form = ProjectForm(request.POST or None, request.FILES or None)
if form.is_valid():
project = form.save(commit=False)
project.save()
messages.success(request, "Directory entry added successfully!", extra_tags='alert-success')
return HttpResponseRedirect("/")
else:
messages.error(request, "Something went wrong! Make sure all field are valid.", extra_tags='alert-warning')
context = {
"form": form
}
return render(request, "projects/add.html", context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment