diff --git a/django_library/urls.py b/django_library/urls.py index 5cd8b91..7f08ccd 100644 --- a/django_library/urls.py +++ b/django_library/urls.py @@ -16,8 +16,9 @@ """ from django.contrib import admin -from django.urls import path +from django.urls import path, include urlpatterns = [ path("admin/", admin.site.urls), + path("library/", include("library.urls")), ] diff --git a/library/templates/library/author_detail.html b/library/templates/library/author_detail.html new file mode 100644 index 0000000..f636522 --- /dev/null +++ b/library/templates/library/author_detail.html @@ -0,0 +1,50 @@ +{% extends 'library/base.html' %} + +{% block title %}{{ author.name }}{% endblock %} + +{% block content %} +
+
+

{{ author.name }}

+ {% if author.website %} + + Visitar sitio web + + {% endif %} + +
+

{{ author.bio }}

+
+
+
+ +

Libros de {{ author.name }}

+
+ {% for book in author.book_set.all %} +
+
+
+
{{ book.title }}
+

+ Publicado: {{ book.published_date }} +

+ {% if book.is_available %} + Disponible + {% else %} + No Disponible + {% endif %} + +
+
+
+ {% empty %} +
+
+ Este autor aún no tiene libros registrados. +
+
+ {% endfor %} +
+{% endblock %} diff --git a/library/templates/library/author_list.html b/library/templates/library/author_list.html new file mode 100644 index 0000000..98342c8 --- /dev/null +++ b/library/templates/library/author_list.html @@ -0,0 +1,34 @@ +{% extends 'library/base.html' %} + +{% block title %}Autores{% endblock %} + +{% block content %} +

Autores

+ +
+ {% for author in authors %} +
+
+
+
{{ author.name }}
+

{{ author.bio|truncatewords:30 }}

+
+ Ver detalles + {% if author.website %} + + Sitio web + + {% endif %} +
+
+
+
+ {% empty %} +
+
+ No hay autores registrados. +
+
+ {% endfor %} +
+{% endblock %} diff --git a/library/templates/library/base.html b/library/templates/library/base.html new file mode 100644 index 0000000..8eb088b --- /dev/null +++ b/library/templates/library/base.html @@ -0,0 +1,36 @@ + + + + + + {% block title %}Biblioteca Django{% endblock %} + + + + + +
+ {% block content %} + {% endblock %} +
+ + + + diff --git a/library/templates/library/book_detail.html b/library/templates/library/book_detail.html new file mode 100644 index 0000000..5b25c14 --- /dev/null +++ b/library/templates/library/book_detail.html @@ -0,0 +1,30 @@ +{% extends 'library/base.html' %} + +{% block title %}{{ book.title }}{% endblock %} + +{% block content %} +
+
+

{{ book.title }}

+

+ por {{ book.author.name }} +

+ +
+
+

Fecha de publicación: {{ book.published_date }}

+
+
+

+ Estado: + {% if book.is_available %} + Disponible + {% else %} + No Disponible + {% endif %} +

+
+
+
+
+{% endblock %} diff --git a/library/templates/library/custom_book_list.html b/library/templates/library/custom_book_list.html new file mode 100644 index 0000000..d9d764f --- /dev/null +++ b/library/templates/library/custom_book_list.html @@ -0,0 +1,32 @@ +{% extends 'library/base.html' %} + +{% block title %}Libros Disponibles{% endblock %} + +{% block content %} +

Libros Disponibles

+ +
+ {% for book in books %} +
+
+
+
{{ book.title }}
+
+ {{ book.author.name }} +
+

+ Publicado: {{ book.published_date }} +

+ Ver detalles +
+
+
+ {% empty %} +
+
+ No hay libros disponibles en este momento. +
+
+ {% endfor %} +
+{% endblock %} diff --git a/library/urls.py b/library/urls.py new file mode 100644 index 0000000..5091172 --- /dev/null +++ b/library/urls.py @@ -0,0 +1,11 @@ +from django.urls import path +from django.shortcuts import redirect +from . import views + +urlpatterns = [ + path("", lambda request: redirect("book_list", permanent=True)), + path("books/", views.BookListView.as_view(), name="book_list"), + path("books//", views.BookDetailView.as_view(), name="book_detail"), + path("authors/", views.AuthorListView.as_view(), name="author_list"), + path("authors//", views.AuthorDetailView.as_view(), name="author_detail"), +] diff --git a/library/views.py b/library/views.py index 91ea44a..8e8768b 100644 --- a/library/views.py +++ b/library/views.py @@ -1,3 +1,22 @@ -from django.shortcuts import render +from django.views.generic import ListView, DetailView +from .models import Book, Author -# Create your views here. + +class BookListView(ListView): + model = Book + template_name = "library/custom_book_list.html" + queryset = Book.objects.filter(is_available=True) + context_object_name = "books" + + +class BookDetailView(DetailView): + model = Book + + +class AuthorListView(ListView): + model = Author + context_object_name = "authors" + + +class AuthorDetailView(DetailView): + model = Author