def category_create(request): if request.method == 'POST': form = CategoryForm(data=request.POST) if form.is_valid(): form.save() return redirect(reverse("foro:admin-category-list")) else: form = CategoryForm() return render(request, 'foro/admin/category/category_create.html', {'form': form, })
def category_create(request): if request.method == 'POST': form = CategoryForm(data=request.POST) if form.is_valid(): form.save() return redirect(reverse("foro:admin-category-list")) else: form = CategoryForm() return render(request, 'foro/admin/category/category_create.html', { 'form': form, })
def category_update(request, category_id): category = get_object_or_404(Category, pk=category_id) if request.method == 'POST': form = CategoryForm(data=request.POST, instance=category) if form.is_valid(): form.save() messages.info(request, _("The category has been updated!")) return redirect(reverse("foro:admin-category-list")) else: form = CategoryForm(instance=category) return render(request, 'foro/admin/category/category_update.html', {'form': form, })
def category_update(request, category_id): category = get_object_or_404(Category, pk=category_id) if request.method == 'POST': form = CategoryForm(data=request.POST, instance=category) if form.is_valid(): form.save() messages.info(request, _("The category has been updated!")) return redirect(reverse("foro:admin-category-list")) else: form = CategoryForm(instance=category) return render(request, 'foro/admin/category/category_update.html', { 'form': form, })