Commit 8493324d authored by Jan Ericsson Ong Ang's avatar Jan Ericsson Ong Ang

fixed views.py and urls.py to show books & author

parent 1b9b05cd
...@@ -14,6 +14,6 @@ ...@@ -14,6 +14,6 @@
<a href="/bookshelf/">Home</a>&nbsp;&nbsp; <a href="/bookshelf/">Home</a>&nbsp;&nbsp;
<a href="/bookshelf/books/">Books</a>&nbsp;&nbsp; <a href="/bookshelf/books/">Books</a>&nbsp;&nbsp;
<a href="/bookshelf/author/">Authors</a> <a href="/bookshelf/authors/">Authors</a>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
{% block header %}<h1>{{ nickname }}'s Favorite Authors:</h1>{% endblock %} {% block header %}<h1>{{ nickname }}'s Favorite Authors:</h1>{% endblock %}
<br> <br>
{% for author in authors %} {% for author in authors %}
<a href="/bookshelf/author/{{ author.pk }}/details/">{{ author.first_name }} {{ author.last_name }}</a> <a href="/bookshelf/authors/{{ author.pk }}/details/">{{ author.first_name }} {{ author.last_name }}</a>
{% endfor %} {% endfor %}
<br> <br>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
{% block content %} {% block content %}
{% block header %}<h1>{{ books.title }}</h1>{% endblock %} {% block header %}<h1>{{ books.title }}</h1>{% endblock %}
<a href="/bookshelf/author/{{ books.author.pk }}/details/">{{ books.author.pk }}</a><br> <a href="/bookshelf/authors/{{ books.author.pk }}/details/">{{ books.author.pk }}</a><br>
<p>{{ books.publisher }}</p> <p>{{ books.publisher }}</p>
<p>{{ books.year_published }}</p> <p>{{ books.year_published }}</p>
<p>{{ books.year_ISBN }}</p> <p>{{ books.year_ISBN }}</p>
...@@ -13,6 +13,6 @@ ...@@ -13,6 +13,6 @@
<a href="/bookshelf/">Home</a>&nbsp;&nbsp; <a href="/bookshelf/">Home</a>&nbsp;&nbsp;
<a href="/bookshelf/books/">Books</a>&nbsp;&nbsp; <a href="/bookshelf/books/">Books</a>&nbsp;&nbsp;
<a href="/bookshelf/author/">Authors</a> <a href="/bookshelf/authors/">Authors</a>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -12,6 +12,6 @@ ...@@ -12,6 +12,6 @@
<br> <br>
<a href="/bookshelf/">Home</a>&nbsp;&nbsp; <a href="/bookshelf/">Home</a>&nbsp;&nbsp;
<a href="/bookshelf/author/">Authors</a> <a href="/bookshelf/authors/">Authors</a>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -10,6 +10,6 @@ ...@@ -10,6 +10,6 @@
</p> </p>
<a href="/bookshelf/books/">Books</a> <a href="/bookshelf/books/">Books</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="/bookshelf/author/">Authors</a> <a href="/bookshelf/authors/">Authors</a>
{% endblock %} {% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from . import views
from .views import HomeView, AuthorView, AuthorDetailView, BooksView, BookDetailView from .views import HomeView, AuthorView, AuthorDetailView, BooksView, BookDetailView
# url for bookshelf # url for bookshelf
urlpatterns = [ urlpatterns = [
path('', HomeView.as_view(), name='home'), path('', views.HomeView, name='home'),
path('author/', AuthorView.as_view(), name='author'), path('authors/', AuthorView.as_view(), name='authors'),
path('author/<int:pk>/details/', AuthorDetailView.as_view(), name='author-detail'), path('authors/<int:pk>/details/', AuthorDetailView.as_view(), name='author-detail'),
path('books/', BooksView.as_view(), name='books'), path('books/', BooksView.as_view(), name='books'),
path('books/<int:pk>/details/', BookDetailView.as_view(), name='books-detail'), path('books/<int:pk>/details/', BookDetailView.as_view(), name='books-detail'),
] ]
......
...@@ -6,24 +6,24 @@ from .models import Author, Books ...@@ -6,24 +6,24 @@ from .models import Author, Books
# Create your views here. # Create your views here.
class HomeView(View): def HomeView(request):
def get(self, request):
return render(request, 'bookshelf/home.html', {'nickname': 'Jan'}) return render(request, 'bookshelf/home.html', {'nickname': 'Jan'})
class AuthorView(ListView): class AuthorView(ListView):
model = Author
def get(self, request): def get(self, request):
return render(request, 'bookshelf/author.html', {'nickname': 'Jan'}) model = Author
return render(request, 'bookshelf/authors.html', {'nickname': 'Jan'})
class AuthorDetailView(DetailView): class AuthorDetailView(DetailView):
model = Author model = Author
template_name = 'bookshelf/author_details.html' template_name = 'bookshelf/author_details.html'
class BooksView(ListView): class BooksView(ListView):
model = Books
def get(self, request): def get(self, request):
model = Books
return render(request, 'bookshelf/books.html', {'nickname': 'Jan'}) return render(request, 'bookshelf/books.html', {'nickname': 'Jan'})
class BookDetailView(DetailView): class BookDetailView(DetailView):
model = Books model = Books
template_name = 'bookshelf/books_details.html' template_name = 'bookshelf/books_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