Commit 372ad12e authored by Ross Batacan's avatar Ross Batacan

added Add Book link on homepage and created add-book.html

parent b5747190
...@@ -7,5 +7,9 @@ ...@@ -7,5 +7,9 @@
<a href="{% url 'bookshelf:books' %}">Books</a> <a href="{% url 'bookshelf:books' %}">Books</a>
&nbsp&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp&nbsp
<a href="{% url 'bookshelf:authors' %}">Authors</a> <a href="{% url 'bookshelf:authors' %}">Authors</a>
&nbsp&nbsp&nbsp&nbsp
<br> <br> <a href="{% url 'bookshelf:book-add' %}">Add Book</a>
&nbsp&nbsp&nbsp&nbsp
{% endblock %} {% endblock %}
from django.urls import path from django.urls import path
from . import views from . import views
from .views import BooksListView, BooksDetailsView, AuthorsListView, AuthorDetailsView from .views import BooksListView, BooksDetailsView, AuthorsListView, AuthorDetailsView, BookCreateView
urlpatterns = [ urlpatterns = [
path('home/', views.home, name = "home"), path('home/', views.home, name="home"),
path('books/', BooksListView.as_view(), name = "books"), path('books/', BooksListView.as_view(), name="books"),
path('books/<int:pk>/details/', BooksDetailsView.as_view(), name = "book-detail"), path('books/<int:pk>/details/', BooksDetailsView.as_view(), name="book-detail"),
path('authors/', AuthorsListView.as_view(), name = "authors"), path('authors/', AuthorsListView.as_view(), name="authors"),
path('authors/<int:pk>/details/', AuthorDetailsView.as_view(), name = "author-detail"), path('authors/<int:pk>/details/', AuthorDetailsView.as_view(), name="author-detail"),
path('books/add', BookCreateView.as_view(), name='book-add')
] ]
app_name = 'bookshelf' app_name = 'bookshelf'
from django.shortcuts import render from django.shortcuts import render
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Author, Books from .models import Author, Books
...@@ -24,3 +25,8 @@ class AuthorsListView(ListView): ...@@ -24,3 +25,8 @@ class AuthorsListView(ListView):
class AuthorDetailsView(DetailView): class AuthorDetailsView(DetailView):
model = Author model = Author
template_name = 'bookshelf/author_details.html' template_name = 'bookshelf/author_details.html'
class BookCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/add-book.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