예제 #1
0
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'))
예제 #2
0
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'))
예제 #3
0
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'))
예제 #4
0
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'))