Updated for the implementation of the added template pages

parent 4fdbb534
......@@ -121,7 +121,7 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/
STATIC_URL = 'static/'
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
# Default primary key field type
......
from django.urls import path
from .views import index, homepage, BookListView, BookDetailView, AuthorListView, AuthorDetailView
from .views import (index, homepage, BookListView, BookDetailView, BookCreateView, BookUpdateView,
AuthorListView, AuthorDetailView, AuthorCreateView, AuthorUpdateView
)
urlpatterns = [
......@@ -8,8 +10,12 @@ urlpatterns = [
path('home', homepage, name='home'),
path('books', BookListView.as_view(), name='books-list'),
path('books/<int:pk>/details', BookDetailView.as_view(), name='books-detail'),
path('books/add', BookCreateView.as_view(), name ='books-create'),
path('books/<int:pk>/edit', BookUpdateView.as_view(), name ='books-update'),
path('authors', AuthorListView.as_view(), name='authors-list'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='authors-detail'),
path('authors/add', AuthorCreateView.as_view(), name='authors-create'),
path('authors/<int:pk>/edit', AuthorUpdateView.as_view(), name ='authors-update')
]
app_name = "bookshelf"
......@@ -3,6 +3,7 @@ from django.http import HttpResponse
from django.views import View
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Books, Author
......@@ -21,6 +22,16 @@ class BookDetailView(DetailView):
model = Books
template_name = 'bookshelf/book_details.html'
class BookCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/add-book.html'
class BookUpdateView(UpdateView):
model = Books
fields = '__all__'
template_name ="bookshelf/edit-book.html"
class AuthorListView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
......@@ -34,3 +45,12 @@ class AuthorDetailView(DetailView):
context['books'] = Books.objects.all()
return context
class AuthorCreateView(CreateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/add-author.html'
class AuthorUpdateView(UpdateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/edit-author.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