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

Created views for author and author_details. Made necessary changes in other files.

parent a566fc1e
Pipeline #3062 canceled with stages
...@@ -13,6 +13,9 @@ class Author(models.Model): ...@@ -13,6 +13,9 @@ class Author(models.Model):
def __str__(self): def __str__(self):
return self.first_name + " " + self.last_name return self.first_name + " " + self.last_name
def get_absolute_url(self):
return reverse('bookshelf:author-detail', kwargs={'pk': self.pk})
class Book(models.Model): class Book(models.Model):
title = models.CharField(max_length=50) title = models.CharField(max_length=50)
author = models.ForeignKey(Author, on_delete=models.CASCADE) author = models.ForeignKey(Author, on_delete=models.CASCADE)
......
{% extends 'base.html' %}
{% block title %}{{ object.first_name }} {{ object.last_name }}{% endblock %}
{% block content %}
<h1>{{ object.first_name }} {{ object.last_name }}</h1>
<p>
{{ object.age }}<br>
{{ object.nationality }}<br>
{{ object.bio }}<br>
Books by {{ object.first_name }} {{ object.last_name }} I love:
</p>
<ul>
{% for book in object.book_set.all %}
<li>
<a href="{{ book.get_absolute_url }}">{{ book.title }}</a>
</li>
{% endfor %}
</ul>
<a href="{% url 'bookshelf:home' %}">Home</a>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<a href="{% url 'bookshelf:books' %}">Books</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' %} {% extends 'base.html' %}
{% block title %}My Favorite Authors{% endblock %} {% block title %}My Favorite Authors{% endblock %}
{% block content %} {% block content %}
<h1>{{name}}'s Favorite Authors:</h1> <h1>Mav's Favorite Authors:</h1>
<p>Mav like Japanese manga with authors that writes in a serious tone.</p> <ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}"> {{ object.first_name }} {{ object.last_name }} </a>
</li>
{% endfor %}
</ul>
<a href="{% url 'bookshelf:home' %}">Home</a>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<a href="{% url 'bookshelf:books' %}">Books</a>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
{% block content %} {% block content %}
<h1>{{ object.title }}</h1> <h1>{{ object.title }}</h1>
<p> <p>
{{ object.author }}<br> <a href="{{ object.author.get_absolute_url }}">{{ object.author }}</a><br>
{{ object.publisher }}<br> {{ object.publisher }}<br>
{{ object.year_published }}<br> {{ object.year_published }}<br>
{{ object.ISBN }}<br> {{ object.ISBN }}<br>
......
from django.urls import path from django.urls import path
from . import views from . import views
from .views import BooksListView, BookDetailsView from .views import BooksListView, BookDetailsView, AuthorsListView, AuthorDetailsView
urlpatterns = [ urlpatterns = [
path('home/', views.home_view, name = "home"), path('home/', views.home_view, name = "home"),
path('books/', BooksListView.as_view(), name = "books"), path('books/', BooksListView.as_view(), name = "books"),
path('books/<int:pk>/details', BookDetailsView.as_view(), name = "book-detail"), path('books/<int:pk>/details/', BookDetailsView.as_view(), name = "book-detail"),
path('authors/', views.authors_view, name = "authors"), path('authors/', AuthorsListView.as_view(), name = "authors"),
path('authors/<int:pk>/details/', AuthorDetailsView.as_view(), name = "author-detail"),
] ]
app_name = 'bookshelf' app_name = 'bookshelf'
\ No newline at end of file
...@@ -9,11 +9,6 @@ from .models import Author, Book ...@@ -9,11 +9,6 @@ from .models import Author, Book
def home_view(request): def home_view(request):
return render(request, 'bookshelf/home.html') return render(request, 'bookshelf/home.html')
def authors_view(request):
return render(request, 'bookshelf/authors.html', {
'name': 'Mav',
})
class BooksListView(ListView): class BooksListView(ListView):
model = Book model = Book
template_name = 'bookshelf/books.html' template_name = 'bookshelf/books.html'
...@@ -21,3 +16,11 @@ class BooksListView(ListView): ...@@ -21,3 +16,11 @@ class BooksListView(ListView):
class BookDetailsView(DetailView): class BookDetailsView(DetailView):
model = Book model = Book
template_name = 'bookshelf/book_details.html' template_name = 'bookshelf/book_details.html'
class AuthorsListView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
class AuthorDetailsView(DetailView):
model = Author
template_name = 'bookshelf/author_details.html'
\ No newline at end of file
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