Commit c21824e5 authored by Gabriel G. Garrero's avatar Gabriel G. Garrero

Edited urls.py and views.py to account for the add book function

parent d027a198
from django.urls import path from django.urls import path
from .views import ( from .views import (
home, BooksListView, BooksDetailView, home, BooksListView, BooksDetailView, BooksCreateView,
AuthorListView, AuthorDetailView AuthorListView, AuthorDetailView
) )
...@@ -8,6 +8,7 @@ urlpatterns = [ ...@@ -8,6 +8,7 @@ urlpatterns = [
path('home/', home, name = 'home'), path('home/', home, name = 'home'),
path('books/', BooksListView.as_view(), name = 'book-list'), path('books/', BooksListView.as_view(), name = 'book-list'),
path('books/<int:pk>/details', BooksDetailView.as_view(), name = 'books-details'), path('books/<int:pk>/details', BooksDetailView.as_view(), name = 'books-details'),
path('books/add', BooksCreateView.as_view(), name = 'add-book'),
path('authors/', AuthorListView.as_view(), name = 'author-list'), path('authors/', AuthorListView.as_view(), name = 'author-list'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name = 'author-details'), path('authors/<int:pk>/details', AuthorDetailView.as_view(), name = 'author-details'),
] ]
......
...@@ -2,6 +2,7 @@ from django.shortcuts import render ...@@ -2,6 +2,7 @@ from django.shortcuts import render
from django.views import View from django.views import View
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
from .models import Author, Books from .models import Author, Books
def home(request): def home(request):
...@@ -14,6 +15,11 @@ class BooksListView(ListView): ...@@ -14,6 +15,11 @@ class BooksListView(ListView):
class BooksDetailView(DetailView): class BooksDetailView(DetailView):
model = Books model = Books
template_name = 'bookshelf/book_details.html' template_name = 'bookshelf/book_details.html'
class BooksCreateView(CreateView):
model = Books
template_name = 'bookshelf/add-book.html'
fields = '__all__'
class AuthorListView(ListView): class AuthorListView(ListView):
model = Author model = Author
......
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