Commit 0ec9f924 authored by Ciella's avatar Ciella

Updated views and URLs

parent 14590bb9
...@@ -6,8 +6,12 @@ urlpatterns = [ ...@@ -6,8 +6,12 @@ urlpatterns = [
path('home/', home_view, name='home_view'), path('home/', home_view, name='home_view'),
path('books/', BooksListView.as_view(), name='books_list'), path('books/', BooksListView.as_view(), name='books_list'),
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('books/<int:pk>/edit/', BooksUpdateView.as_view(), name='edit-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'),
path('authors/add/', AuthorCreateView.as_view(), name='add-author'),
path('authors/<int:pk>/edit/', AuthorUpdateView.as_view(), name='edit-author'),
] ]
app_name = 'bookshelf' app_name = 'bookshelf'
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, UpdateView
from .models import Author, Books from .models import Author, Books
...@@ -18,6 +19,18 @@ class AuthorListView(ListView): ...@@ -18,6 +19,18 @@ class AuthorListView(ListView):
template_name = 'bookshelf/authors.html' template_name = 'bookshelf/authors.html'
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'
class BooksDetailView(DetailView): class BooksDetailView(DetailView):
model = Books model = Books
template_name = 'bookshelf/book_details.html' template_name = 'bookshelf/book_details.html'
...@@ -26,3 +39,15 @@ class BooksDetailView(DetailView): ...@@ -26,3 +39,15 @@ class BooksDetailView(DetailView):
class BooksListView(ListView): class BooksListView(ListView):
model = Books model = Books
template_name = 'bookshelf/books.html' template_name = 'bookshelf/books.html'
class BooksCreateView(CreateView):
model = Books
fields = "__all__"
template_name = 'bookshelf/add-book.html'
class BooksUpdateView(UpdateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/edit-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