def post(self, request, *args, **kwargs): obj = self.get_object() form = CourseModelForm(request.POST, instance=obj) if form.is_valid(): form.save() context = {"form": form} return render(request, "courses/update.html", context)
def add(request): if request.method == "POST": form = CourseModelForm(request.POST) if form.is_valid(): data = form.cleaned_data form.save() messages.success(request, 'Course {} has been successfully added.'.format(data['name'])) return redirect('/') else: form = CourseModelForm() return render(request, "courses/add.html", {'form':form})
def post(self, request, *args, **kwargs): form = CourseModelForm(request.POST) if form.is_valid(): form.save() context = {"form": form} return render(request, "courses/create.html", context)