Commit ea85720d authored by Tanya Yotoko's avatar Tanya Yotoko

Edited urls.py and views.py with the necessary attributes

parent c3fd9f39
from django.urls import path from django.urls import path
from .views import index, homepage, BooksView, AuthorsView, BooksDetailView, AuthorsDetailView
from .views import (index, homepage, BooksView, AuthorsView, BooksDetailView, AuthorsDetailView, BooksCreateView, BooksUpdateView, AuthorsCreateView, AuthorsUpdateView
)
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', index, name='index'),
...@@ -8,6 +10,10 @@ urlpatterns = [ ...@@ -8,6 +10,10 @@ urlpatterns = [
path('authors/',AuthorsView.as_view(),name='authors'), path('authors/',AuthorsView.as_view(),name='authors'),
path('books/<int:pk>/details/',BooksDetailView.as_view(),name='book_details'), path('books/<int:pk>/details/',BooksDetailView.as_view(),name='book_details'),
path('authors/<int:pk>/details/',AuthorsDetailView.as_view(),name='author_details'), path('authors/<int:pk>/details/',AuthorsDetailView.as_view(),name='author_details'),
path('books/add/',BooksCreateView.as_view(),name='add-book'),
path('books/<pk>/edit/',BooksUpdateView.as_view(),name='edit-book'),
path('authors/add/',AuthorsCreateView.as_view(),name='add-author'),
path('authors/<pk>/edit/',AuthorsUpdateView.as_view(),name='edit-author'),
] ]
app_name = "bookshelf" app_name = "bookshelf"
\ No newline at end of file
...@@ -3,6 +3,7 @@ from django.shortcuts import render ...@@ -3,6 +3,7 @@ from django.shortcuts import render
from .models import Author, Book from .models import Author, Book
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
def index(request): def index(request):
return HttpResponse('Hello! This came from the index view') return HttpResponse('Hello! This came from the index view')
...@@ -18,6 +19,16 @@ class BooksDetailView(DetailView): ...@@ -18,6 +19,16 @@ class BooksDetailView(DetailView):
model = Book model = Book
template_name = "bookshelf/book_details.html" template_name = "bookshelf/book_details.html"
class BooksCreateView(CreateView):
model = Book
fields = '__all__'
template_name = 'bookshelf/add-book.html'
class BooksUpdateView(UpdateView):
model = Book
fields = '__all__'
template_name = 'bookshelf/edit-book.html'
class AuthorsView(ListView): class AuthorsView(ListView):
model = Author model = Author
template_name = "bookshelf/authors.html" template_name = "bookshelf/authors.html"
...@@ -26,3 +37,12 @@ class AuthorsDetailView(DetailView): ...@@ -26,3 +37,12 @@ class AuthorsDetailView(DetailView):
model = Author model = Author
template_name = "bookshelf/author_details.html" template_name = "bookshelf/author_details.html"
class AuthorsCreateView(CreateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/add-author.html'
class AuthorsUpdateView(UpdateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/edit-author.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