Commit 6db6428a authored by Julia Anishka's avatar Julia Anishka

added new book page

parent e2c3c4a5
from django.urls import path from django.urls import path
from . import views from . import views
from .views import BooksListView, BooksDetailView, AuthorsListView, AuthorsDetailView from .views import (BooksListView, BooksDetailView, BooksCreateView, AuthorsListView,
AuthorsDetailView, )
urlpatterns = [ urlpatterns = [
path('home/', views.homepage_view, name='home'), path('home/', views.homepage_view, name='home'),
path('books/', BooksListView.as_view(), name='books'), path('books/', BooksListView.as_view(), name='books'),
path('books/<int:pk>/details/', BooksDetailView.as_view(), name='book_details'), path('books/<int:pk>/details/', BooksDetailView.as_view(), name='book_details'),
path('books/add/', BooksCreateView.as_view(), name='add-book'),
path('authors/', AuthorsListView.as_view(), name='authors'), path('authors/', AuthorsListView.as_view(), name='authors'),
path('authors/<int:pk>/details/', AuthorsDetailView.as_view(), name='author_details') path('authors/<int:pk>/details/', AuthorsDetailView.as_view(), name='author_details')
] ]
......
...@@ -3,6 +3,7 @@ from django.http import HttpResponse ...@@ -3,6 +3,7 @@ from django.http import HttpResponse
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
...@@ -23,6 +24,11 @@ class BooksDetailView(DetailView): ...@@ -23,6 +24,11 @@ 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 AuthorsListView(ListView): class AuthorsListView(ListView):
model = Author model = Author
template_name = 'bookshelf/authors.html' template_name = 'bookshelf/authors.html'
...@@ -30,3 +36,4 @@ class AuthorsListView(ListView): ...@@ -30,3 +36,4 @@ class AuthorsListView(ListView):
class AuthorsDetailView(DetailView): class AuthorsDetailView(DetailView):
model = Author model = Author
template_name = 'bookshelf/author_details.html' template_name = 'bookshelf/author_details.html'
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