def categories(request): form = CategoryForm(board = request.board) categories = Category.objects.all() if request.method == "POST": form = CategoryForm(data = request.POST, board = request.board) if form.is_valid(): category = form.save(commit = False) category.board = request.board category.save() request.user.message_set.create(message = "The category %s has been added." % category.name) return HttpResponseRedirect(".") extra = {"form": form} return object_list(request, queryset = categories, template_name = 'zobpress/categories.html', template_object_name = 'category', extra_context = extra)
def edit_category(request, category_pk): category = get_object_or_404(Category, board = request.board, pk = category_pk) form = CategoryForm(instance = category, board = request.board) if request.method == "POST": form = CategoryForm(instance = category, data = request.POST, board = request.board) if form.is_valid(): form.save() messages.success(request,'The category has been successfully renamed') return redirect(categories) payload = dict(category=category, form=form) return render_to_response("zobpress/edit_category.html", payload, RequestContext(request))