Example #1
0
def index(request):
    data = {}
    if request.method == 'POST':
        form = CategoryForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/category/success')
    else:
        form = CategoryForm()
    list_item = Category.objects.all()
    data['id'] = None
    data['list_item'] = list_item
    data['form'] = form
    return render(request, 'category/index.html', data)
Example #2
0
def update_item(request, id):
    data = {}
    try:
        selected_item = Category.objects.get(pk=id)
        form = CategoryForm(instance=selected_item)
    except Category.DoesNotExist:
        raise Http404("This item not exist.")
    if request.method == 'POST':
        form = CategoryForm(request.POST or None, instance=selected_item)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/category/success')
    list_item = Category.objects.all()
    data['id'] = id
    data['list_item'] = list_item
    data['form'] = form
    return render(request, 'category/index.html', data)
Example #3
0
def index(request):
   data = {}
   if request.method == 'POST':
       form = CategoryForm(request.POST)
       if form.is_valid():
           form.save()
           return HttpResponseRedirect('/category/success')
   else:
       form = CategoryForm()
   list_item = Category.objects.all()
   data['id'] = None
   data['list_item'] = list_item
   data['form'] = form
   return render(
       request,
       'category/index.html',
       data
   )
Example #4
0
def update_item(request, id):
   data = {}
   try:
       selected_item = Category.objects.get(pk=id)
       form = CategoryForm(instance=selected_item)
   except Category.DoesNotExist:
       raise Http404("This item not exist.")
   if request.method == 'POST':
       form = CategoryForm(request.POST or None, instance=selected_item)
       if form.is_valid():
           form.save()
           return HttpResponseRedirect('/category/success')
   list_item = Category.objects.all()
   data['id'] = id
   data['list_item'] = list_item
   data['form'] = form
   return render(
       request,
       'category/index.html',
       data
   )