def addCategory(request): template = 'zxc/addCategory.html' if request.method=='GET': return render(request, template, {'form':CategoryForm()}) # request.method=='POST' form = CategoryForm(request.POST) if not form.is_valid(): return render(request, template, {'form':form}) form.save() return redirect(reverse('zxc:zxc'))
def updateCategory(request, categoryID): template = 'zxc/updateCategory.html' try: category = Category.objects.get(id=categoryID) except Category.DoesNotExist: return zxc(request) if request.method=='GET': form = CategoryForm(instance=category) return render(request, template, {'form':form, 'category':category}) # request.method=='POST' form = CategoryForm(request.POST, instance=category) if not form.is_valid(): return render(request, template, {'form':form, 'category':category}) form.save() return redirect(reverse('zxc:zxc'))
def addCategory(request): template = 'zxc/addCategory.html' if request.method == 'GET': return render(request, template, {'form': CategoryForm()}) # request.method=='POST' form = CategoryForm(request.POST) if not form.is_valid(): return render(request, template, {'form': form}) form.save() return redirect(reverse('zxc:zxc'))
def updateCategory(request, categoryID): template = 'zxc/updateCategory.html' try: category = Category.objects.get(id=categoryID) except Category.DoesNotExist: return zxc(request) if request.method == 'GET': form = CategoryForm(instance=category) return render(request, template, {'form': form, 'category': category}) # request.method=='POST' form = CategoryForm(request.POST, instance=category) if not form.is_valid(): return render(request, template, {'form': form, 'category': category}) form.save() return redirect(reverse('zxc:zxc'))