def add_category(cls, request): if request.method == 'POST': form = CategoryForm(request.POST) if form.is_valid(): name = request.POST['name'] new_category = Category(name=name) new_category.save() return HttpResponseRedirect("/manager/kategorie/") else: form = CategoryForm() return render_to_response('backpanel_new_category.html', {'form': form}, context_instance=RequestContext(request))
def edit_category(cls, request, id): if request.method == 'POST': form = CategoryForm(request.POST) if form.is_valid(): name = request.POST['name'] category = Category.objects.get(pk=id) category.name=name category.save() return HttpResponseRedirect("/manager/kategorie/") else: category=Category.objects.get(pk=id) category_name=category.name form = CategoryForm(initial={"name":category_name}) return render_to_response('backpanel_new_category.html', {'form': form, 'category_name': category_name}, context_instance=RequestContext(request))
def edit_category(cls, request, id): if request.method == 'POST': form = CategoryForm(request.POST) if form.is_valid(): name = request.POST['name'] category = Category.objects.get(pk=id) category.name = name category.save() return HttpResponseRedirect("/manager/kategorie/") else: category = Category.objects.get(pk=id) category_name = category.name form = CategoryForm(initial={"name": category_name}) return render_to_response('backpanel_new_category.html', { 'form': form, 'category_name': category_name }, context_instance=RequestContext(request))