Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion django_library/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
]
50 changes: 50 additions & 0 deletions library/templates/library/author_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{% extends 'library/base.html' %}

{% block title %}{{ author.name }}{% endblock %}

{% block content %}
<div class="card mb-4">
<div class="card-body">
<h1 class="card-title">{{ author.name }}</h1>
{% if author.website %}
<a href="{{ author.website }}" class="btn btn-outline-primary mb-3" target="_blank">
Visitar sitio web
</a>
{% endif %}

<div class="card-text">
<p>{{ author.bio }}</p>
</div>
</div>
</div>

<h2>Libros de {{ author.name }}</h2>
<div class="row row-cols-1 row-cols-md-3 g-4">
{% for book in author.book_set.all %}
<div class="col">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title">{{ book.title }}</h5>
<p class="card-text">
<small class="text-muted">Publicado: {{ book.published_date }}</small>
</p>
{% if book.is_available %}
<span class="badge bg-success">Disponible</span>
{% else %}
<span class="badge bg-danger">No Disponible</span>
{% endif %}
<div class="mt-2">
<a href="{% url 'book_detail' book.pk %}" class="btn btn-primary">Ver detalles</a>
</div>
</div>
</div>
</div>
{% empty %}
<div class="col-12">
<div class="alert alert-info">
Este autor aún no tiene libros registrados.
</div>
</div>
{% endfor %}
</div>
{% endblock %}
34 changes: 34 additions & 0 deletions library/templates/library/author_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% extends 'library/base.html' %}

{% block title %}Autores{% endblock %}

{% block content %}
<h1 class="mb-4">Autores</h1>

<div class="row row-cols-1 row-cols-md-3 g-4">
{% for author in authors %}
<div class="col">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title">{{ author.name }}</h5>
<p class="card-text">{{ author.bio|truncatewords:30 }}</p>
<div class="d-flex justify-content-between align-items-center">
<a href="{% url 'author_detail' author.pk %}" class="btn btn-primary">Ver detalles</a>
{% if author.website %}
<a href="{{ author.website }}" class="btn btn-outline-secondary" target="_blank">
Sitio web
</a>
{% endif %}
</div>
</div>
</div>
</div>
{% empty %}
<div class="col-12">
<div class="alert alert-info">
No hay autores registrados.
</div>
</div>
{% endfor %}
</div>
{% endblock %}
36 changes: 36 additions & 0 deletions library/templates/library/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}Biblioteca Django{% endblock %}</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="{% url 'book_list' %}">Biblioteca</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="{% url 'book_list' %}">Libros</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'author_list' %}">Autores</a>
</li>
</ul>
</div>
</div>
</nav>

<div class="container mt-4">
{% block content %}
{% endblock %}
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
30 changes: 30 additions & 0 deletions library/templates/library/book_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends 'library/base.html' %}

{% block title %}{{ book.title }}{% endblock %}

{% block content %}
<div class="card">
<div class="card-body">
<h1 class="card-title">{{ book.title }}</h1>
<h3 class="card-subtitle mb-3 text-muted">
por <a href="{% url 'author_detail' book.author.pk %}">{{ book.author.name }}</a>
</h3>

<div class="row mb-3">
<div class="col-md-6">
<p><strong>Fecha de publicación:</strong> {{ book.published_date }}</p>
</div>
<div class="col-md-6">
<p>
<strong>Estado:</strong>
{% if book.is_available %}
<span class="badge bg-success">Disponible</span>
{% else %}
<span class="badge bg-danger">No Disponible</span>
{% endif %}
</p>
</div>
</div>
</div>
</div>
{% endblock %}
32 changes: 32 additions & 0 deletions library/templates/library/custom_book_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% extends 'library/base.html' %}

{% block title %}Libros Disponibles{% endblock %}

{% block content %}
<h1 class="mb-4">Libros Disponibles</h1>

<div class="row row-cols-1 row-cols-md-3 g-4">
{% for book in books %}
<div class="col">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title">{{ book.title }}</h5>
<h6 class="card-subtitle mb-2 text-muted">
<a href="{% url 'author_detail' book.author.pk %}">{{ book.author.name }}</a>
</h6>
<p class="card-text">
<small class="text-muted">Publicado: {{ book.published_date }}</small>
</p>
<a href="{% url 'book_detail' book.pk %}" class="btn btn-primary">Ver detalles</a>
</div>
</div>
</div>
{% empty %}
<div class="col-12">
<div class="alert alert-info">
No hay libros disponibles en este momento.
</div>
</div>
{% endfor %}
</div>
{% endblock %}
11 changes: 11 additions & 0 deletions library/urls.py
Original file line number Diff line number Diff line change
@@ -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/<int:pk>/", views.BookDetailView.as_view(), name="book_detail"),
path("authors/", views.AuthorListView.as_view(), name="author_list"),
path("authors/<int:pk>/", views.AuthorDetailView.as_view(), name="author_detail"),
]
23 changes: 21 additions & 2 deletions library/views.py
Original file line number Diff line number Diff line change
@@ -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