def project_edit(request, project_id): project = get_object_or_404(Project, pk=project_id) if request.method == "POST": form = ProjectForm(request.POST, instance = project) if form.is_valid(): form.save() return redirect('project_list') else: form = ProjectForm(instance = project) return render(request, 'projects/edit.html', {"project" : project, "form" : form})
def project_add(request): if request.method == "POST": form = ProjectForm(request.POST) if form.is_valid(): form.instance.start = datetime.date.today() form.instance.end = datetime.date.today() form.instance.added_by_user = request.user form.save() return redirect('project_list') else: form = ProjectForm() return render(request, 'projects/add.html', {"form": form})
def project_edit(request, project_id): project = get_object_or_404(Project, pk=project_id) if request.method == "POST": form = ProjectForm(request.POST, instance=project) if form.is_valid(): form.save() return redirect('project_list') else: form = ProjectForm(instance=project) return render(request, 'projects/edit.html', { "project": project, "form": form })