Commit f2888102 authored by Mavrick Jordan Lee's avatar Mavrick Jordan Lee

Deleted temporary books view. Added BooksListView cbv in views and made...

Deleted temporary books view. Added BooksListView cbv in views and made necessary changes in models and urls. Fixed books.html to match the expected output.
parent 152d92f9
from django.db import models
from django.urls import reverse
# Create your models here.
......@@ -22,3 +23,6 @@ class Book(models.Model):
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('bookshelf:books-detail', kwargs={'pk': self.pk})
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
<h1>{{name}}'s Favorite Books:</h1>
<p>Mav like Japanese manga with authors that writes in a serious tone.</p>
<h1>Mav's Favorite Books:</h1>
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}"> {{ object }}</a>
</li>
{% endfor %}
</ul>
<a href="{% url 'bookshelf:home' %}">Home</a>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<a href="{% url 'bookshelf:authors' %}">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}My Favorite Books & Authors{% endblock %}
{% block content %}
<h1>Welcome to {{name}}'s Database of Favorite Books and Authors!</h1>
<h1>Welcome to Mav's Database of Favorite Books and Authors!</h1>
<p>Mav like Japanese manga with authors that writes in a serious tone.</p>
<a href="{% url 'books' %}">Books</a>
<a href="{% url 'bookshelf:books' %}">Books</a>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<a href="{% url 'authors' %}">Authors</a>
<a href="{% url 'bookshelf:authors' %}">Authors</a>
{% endblock %}
\ No newline at end of file
from django.urls import path
from . import views
from .views import BooksListView, BooksDetailView
urlpatterns = [
path('home/', views.home_view, name = "home"),
path('book/', views.books_view, name = "books"),
path('books/', BooksListView.as_view(), name = "books"),
path('books/<int:pk>', BooksDetailView.as_view(), name = "books-detail"),
path('authors/', views.authors_view, name = "authors"),
]
app_name = 'bookshelf'
\ No newline at end of file
from django.shortcuts import render
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from .models import Author, Book
# Create your views here.
def home_view(request):
return render(request, 'bookshelf/home.html', {
'name': 'Mav',
})
def books_view(request):
return render(request, 'bookshelf/books.html', {
'name': 'Mav',
})
return render(request, 'bookshelf/home.html')
def authors_view(request):
return render(request, 'bookshelf/authors.html', {
'name': 'Mav',
})
class BooksListView(ListView):
model = Book
template_name = 'bookshelf/books.html'
class BooksDetailView(DetailView):
model = Book
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