示例#1
0
文件: views.py 项目: i32alala/blogJ
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'))
示例#2
0
文件: views.py 项目: i32alala/blogJ
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'))