Added Create and Update Views and URLS

parent 41bdaeaa
...@@ -2,7 +2,8 @@ from django.urls import path ...@@ -2,7 +2,8 @@ from django.urls import path
from . import views from . import views
from .views import (HomeViews, AuthorsDetailsViews, from .views import (HomeViews, AuthorsDetailsViews,
AuthorsViews, BookDetailsViews, AuthorsViews, BookDetailsViews,
BooksViews) BooksViews, BookCreate, AuthorCreate,
BookUpdate, AuthorUpdate)
urlpatterns = [ urlpatterns = [
path('home/', views.HomeViews, name='home'), path('home/', views.HomeViews, name='home'),
...@@ -10,4 +11,8 @@ urlpatterns = [ ...@@ -10,4 +11,8 @@ urlpatterns = [
path('books/', BooksViews.as_view(), name='books'), path('books/', BooksViews.as_view(), name='books'),
path('authors/<int:pk>/details/', AuthorsDetailsViews.as_view(), name='authordetails'), path('authors/<int:pk>/details/', AuthorsDetailsViews.as_view(), name='authordetails'),
path('books/<int:pk>/details/', BookDetailsViews.as_view(), name='bookdetails'), path('books/<int:pk>/details/', BookDetailsViews.as_view(), name='bookdetails'),
path('books/add/', BookCreate.as_view(), name='booknew'),
path('books/<int:pk>/edit/', BookUpdate.as_view(), name='bookedit'),
path('authors/<int:pk>/edit/', AuthorUpdate.as_view(), name='authoredit'),
path('author/add/', AuthorCreate.as_view(), name='authornew'),
] ]
from django.shortcuts import render from django.shortcuts import render
from django.views.generic import ListView, DetailView from django.urls import reverse
from django.views.generic import ListView, DetailView, CreateView, UpdateView
from .models import * from .models import *
...@@ -29,3 +30,40 @@ class AuthorsDetailsViews(DetailView): ...@@ -29,3 +30,40 @@ class AuthorsDetailsViews(DetailView):
class BookDetailsViews(DetailView): class BookDetailsViews(DetailView):
template_name = "book_details.html" template_name = "book_details.html"
model = Book model = Book
class BookCreate(CreateView):
template_name = "add-book.html"
model = Book
fields = '__all__'
def get_success(self):
return reverse('booknew', kwargs = {'pk': self.object.id},
current_app=self.request.resolver_match.namespace)
class AuthorCreate(CreateView):
model = Author
fields = '__all__'
template_name = "add-author.html"
def get_success(self):
return reverse('authornew', kwarg = {'pk': self.object.id},
current_app=self.request.resolver_match.namespace)
class BookUpdate(UpdateView):
model = Book
template_name = "edit-book.html"
fields = '__all__'
def get_success_url(self):
return reverse('bookdetails', kwargs = {'pk': self.object.pk},
current_app=self.request.resolver_match.namespace)
class AuthorUpdate(UpdateView):
model = Author
template_name = "edit-author.html"
fields = '__all__'
def get_success_url(self):
return reverse('authordetails', kwargs = {'pk': self.object.pk},
current_app=self.request.resolver_match.namespace)
\ 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