def insertar_categoria(request): if request.user.is_staff: if request.method == 'POST': form = categoriaForm(request.POST, request.FILES) if form.is_valid(): form.save() return redirect(reverse_lazy('Ccategoria')) else: form = categoriaForm() context = {'form': form} return render(request, 'Blog/insertarCategoria.html', context) else: return redirect(reverse_lazy('index'))
def editarCategoria(request, id_categ): if request.user.is_staff: categoria = Categoria.objects.get(id=id_categ) if request.method == 'POST': form = categoriaForm(request.POST, instance=categoria) if form.is_valid(): formulario = form.save() return redirect(reverse_lazy('Ccategoria')) else: form = categoriaForm(instance=categoria) context = {'form': form} return render(request, 'Blog/editarCategoria.html', context) else: return redirect(reverse_lazy('index'))