|
|
@ -1,4 +1,5 @@ |
|
|
from django.shortcuts import render, get_object_or_404, redirect |
|
|
from django.shortcuts import render, get_object_or_404, redirect |
|
|
|
|
|
from django.contrib.auth.decorators import login_required |
|
|
from .models import Autor, Libro |
|
|
from .models import Autor, Libro |
|
|
from .forms import AutorForm, LibroForm |
|
|
from .forms import AutorForm, LibroForm |
|
|
|
|
|
|
|
|
@ -12,8 +13,12 @@ def lista_autores(request): |
|
|
|
|
|
|
|
|
def detalle_autor(request, autor_id): |
|
|
def detalle_autor(request, autor_id): |
|
|
autor = get_object_or_404(Autor, pk=autor_id) |
|
|
autor = get_object_or_404(Autor, pk=autor_id) |
|
|
return render(request, 'gestion/detalle_autor.html', {'autor': autor}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
libros = Libro.objects.filter(autor=autor_id) |
|
|
|
|
|
|
|
|
|
|
|
return render(request, 'gestion/detalle_autor.html', {'autor': autor, 'libros': libros}) |
|
|
|
|
|
|
|
|
|
|
|
@login_required |
|
|
def nuevo_autor(request): |
|
|
def nuevo_autor(request): |
|
|
if request.method == 'POST': |
|
|
if request.method == 'POST': |
|
|
form = AutorForm(request.POST, request.FILES) |
|
|
form = AutorForm(request.POST, request.FILES) |
|
|
@ -24,6 +29,7 @@ def nuevo_autor(request): |
|
|
form = AutorForm() |
|
|
form = AutorForm() |
|
|
return render(request, 'gestion/form_autor.html', {'form': form}) |
|
|
return render(request, 'gestion/form_autor.html', {'form': form}) |
|
|
|
|
|
|
|
|
|
|
|
@login_required |
|
|
def editar_autor(request, autor_id): |
|
|
def editar_autor(request, autor_id): |
|
|
autor = get_object_or_404(Autor, pk=autor_id) |
|
|
autor = get_object_or_404(Autor, pk=autor_id) |
|
|
if request.method == 'POST': |
|
|
if request.method == 'POST': |
|
|
@ -35,6 +41,7 @@ def editar_autor(request, autor_id): |
|
|
form = AutorForm(instance=autor) |
|
|
form = AutorForm(instance=autor) |
|
|
return render(request, 'gestion/form_autor.html', {'form': form}) |
|
|
return render(request, 'gestion/form_autor.html', {'form': form}) |
|
|
|
|
|
|
|
|
|
|
|
@login_required |
|
|
def eliminar_autor(request, autor_id): |
|
|
def eliminar_autor(request, autor_id): |
|
|
autor = get_object_or_404(Autor, pk=autor_id) |
|
|
autor = get_object_or_404(Autor, pk=autor_id) |
|
|
autor.delete() |
|
|
autor.delete() |
|
|
@ -49,6 +56,7 @@ def detalle_libro(request, libro_id): |
|
|
libro = get_object_or_404(Libro, pk=libro_id) |
|
|
libro = get_object_or_404(Libro, pk=libro_id) |
|
|
return render(request, 'gestion/detalle_libro.html', {'libro': libro}) |
|
|
return render(request, 'gestion/detalle_libro.html', {'libro': libro}) |
|
|
|
|
|
|
|
|
|
|
|
@login_required |
|
|
def nuevo_libro(request): |
|
|
def nuevo_libro(request): |
|
|
if request.method == 'POST': |
|
|
if request.method == 'POST': |
|
|
form = LibroForm(request.POST, request.FILES) |
|
|
form = LibroForm(request.POST, request.FILES) |
|
|
@ -59,6 +67,7 @@ def nuevo_libro(request): |
|
|
form = LibroForm() |
|
|
form = LibroForm() |
|
|
return render(request, 'gestion/form_libro.html', {'form': form}) |
|
|
return render(request, 'gestion/form_libro.html', {'form': form}) |
|
|
|
|
|
|
|
|
|
|
|
@login_required |
|
|
def editar_libro(request, libro_id): |
|
|
def editar_libro(request, libro_id): |
|
|
libro = get_object_or_404(Libro, pk=libro_id) |
|
|
libro = get_object_or_404(Libro, pk=libro_id) |
|
|
if request.method == 'POST': |
|
|
if request.method == 'POST': |
|
|
@ -70,6 +79,7 @@ def editar_libro(request, libro_id): |
|
|
form = LibroForm(instance=libro) |
|
|
form = LibroForm(instance=libro) |
|
|
return render(request, 'gestion/form_libro.html', {'form': form}) |
|
|
return render(request, 'gestion/form_libro.html', {'form': form}) |
|
|
|
|
|
|
|
|
|
|
|
@login_required |
|
|
def eliminar_libro(request, libro_id): |
|
|
def eliminar_libro(request, libro_id): |
|
|
libro = get_object_or_404(Libro, pk=libro_id) |
|
|
libro = get_object_or_404(Libro, pk=libro_id) |
|
|
libro.delete() |
|
|
libro.delete() |
|
|
|