def project_add(request):
	if request.method == "POST":
		form = ProjectForm(request.user.id, request.POST)
		if form.is_valid():
			form.instance.owner_id = request.user.id
			form.save()
			form.instance.users.add(request.user)
			return redirect(project_list)
	else:
		form = ProjectForm(request.user.id)

	return render(request, 'projects/add.html', {"form": form})
def project_edit(request, project_id= None):
	project = get_object_or_404(Project, pk=project_id)	
	if project.owned_by(request.user.id):
		if request.method == "POST":
			form = ProjectForm(request.user.id, request.POST, instance = project)
			if form.is_valid():
				try:
					form.save()
					form.instance.users.add(request.user)
					return redirect('project_list')
				except:
					return HttpResponseServerError()
		else:
			form = ProjectForm(request.user.id, instance = project)
	else:
		return HttpResponse("You do not have permission")
	return render(request, 'projects/edit.html', {"form" : form})