def updatePage(request, pageID): template = "windows/updatePage.html" try: page = Page.objects.get(id=pageID) except Page.DoesNotExist: return category(request, "") if request.method == "GET": form = PageForm(instance=page) return render(request, template, {"form": form, "page": page}) # request.method=='POST' form = PageForm(request.POST, instance=page) if not form.is_valid(): return render(request, template, {"form": form, "page": page}) form.save() return redirect(reverse("windows:category", args=(page.category.id,)))
def addPage(request, categoryID): template = "windows/addPage.html" try: pageCategory = Category.objects.get(id=categoryID) except Category.DoesNotExist: return category(request, categoryID) context = {"category": pageCategory} if request.method == "GET": context["form"] = PageForm() return render(request, template, context) # request.method=='POST' form = PageForm(request.POST) context["form"] = form if not form.is_valid(): return render(request, template, context) page = form.save(commit=False) page.category = pageCategory page.save() return redirect(reverse("windows:category", args=(categoryID,)))