Пример #1
0
def entrada_editar(request, id_ent_edi):
    entrada = get_object_or_404(Entrada, pk = id_ent_edi)
    if request.method == 'POST':
        form = EntradaNuevaForm(request.POST, request.FILES, instance = entrada)
        if form.is_valid():
            form.save()
            return redirect(reverse_lazy('entradas:entradas_home'))
    else:
        form = EntradaNuevaForm(instance = entrada)
    context = {'form':form}
    
    return render(request, 'blog/entradas_editar.html', context)
Пример #2
0
def entrada_nueva(request):
	if request.method == 'POST':
		form = EntradaNuevaForm(request.POST, request.FILES)
		if form.is_valid():
			formulario = form.save(commit = False)
			formulario.Autor_id = request.user.id
			formulario.save()
			for item in request.POST.getlist('Categoria'):
				formulario.Categoria.add(item)
			return redirect(reverse_lazy('entradas:entradas_home'))
	else:
		form = EntradaNuevaForm()
	context = {'form':form}

	return render(request, 'blog/entradas_nueva.html', context)