Commit d272edd0 authored by Migs Atienza's avatar Migs Atienza

Finished books.html

parent 6439acda
from django.db import models
from django.urls import reverse
class Author(models.Model):
......@@ -23,4 +24,7 @@ class Book(models.Model):
def __str__(self):
return '{}'.format(self.title)
def get_absolute_url(self):
return reverse('bookshelf:books_details', kwargs={'pk': self.pk})
# Create your models here.
{% extends 'base.html' %}
{% block title %}My Favorite Books{% endblock %}
{% block heading %}<center>Migs' Favorite Books</center>{% endblock %}
{% block content %}<center>
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}">
{{ object.title }}
</a>
</li>
{% endfor %}
</ul>
</center>{% endblock %}
{% block links %}
<center><br/><br/><br/><br/><br/>
<a href="home">Home</a>
<a href="authors">Authors</a></center>
{% endblock %}
from django.urls import path
from .views import index, home_view
from .views import index, home_view, BooksListView, BooksDetailView
urlpatterns = [
path('', index, name='index'),
path('home', home_view, name='home_view')
path('home', home_view, name='home_view'),
path('books', BooksListView.as_view(), name='books_list'),
path('books/<int:pk>/details', BooksDetailView.as_view(), name='books_details'),
]
app_name = "<bookshelf>"
......
from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.http import HttpResponse
from .models import Author, Book
def index(request):
return request('Hello World! This came from the index view')
def home_view(request):
return render(request, 'bookshelf/home.html')
class BooksListView(ListView):
model = Book
template_name = "bookshelf/books.html"
class BooksDetailView(DetailView):
model = Book
template_name = "bookshelf/books_details.html"
# Create your views here.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment