def add_obj(request): form = ObjectiveForm(request.POST or None) if request.method == "POST" and form.is_valid(): o = form.save(commit=False) o.user = request.user o.save() return HttpResponseRedirect(reverse('okr:index')) return render(request, "okr/add_obj.html", {'form': form})
def add_obj(request): form = ObjectiveForm(request.POST or None) if request.method == "POST" and form.is_valid(): o = form.save(commit=False) o.user = request.user o.save() return redirect('okr:index') return render(request, "okr/add_obj.html", {'form': form})
def edit_obj(request, id): obj = get_object_or_404(Objective, id=id, user=request.user) if request.method == "POST": form = ObjectiveForm(request.POST, instance=obj) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('okr:index')) else: form = ObjectiveForm(instance=obj) context = { 'form': form, 'objective': obj } return render(request, "okr/edit_obj.html", context)
def edit_obj(request, id): obj = get_object_or_404(Objective, id=id, user=request.user) if request.method == "POST": form = ObjectiveForm(request.POST, instance=obj) if form.is_valid(): form.save() return redirect('okr:index') else: form = ObjectiveForm(instance=obj) context = { 'form': form, 'objective': obj } return render(request, "okr/edit_obj.html", context)
def create_obj_form(name, end_date): return ObjectiveForm(data={'name': name, 'end_date': end_date, })