Added edit feature for books and author

parent c3d35d4d
from django.urls import path from django.urls import path
from .views import ( from .views import (
BooksListView, BooksDetailView, AuthorsDetailView, AuthorsListView, HomepageView, AuthorCreateView, BooksCreateView BooksListView, BooksDetailView, AuthorsDetailView, AuthorsListView,
HomepageView, AuthorCreateView, BooksCreateView, BooksUpdateView,
AuthorUpdateView
) )
urlpatterns = [ urlpatterns = [
...@@ -12,4 +14,6 @@ urlpatterns = [ ...@@ -12,4 +14,6 @@ urlpatterns = [
path('home/', HomepageView, name='home'), path('home/', HomepageView, name='home'),
path('authors/add/', AuthorCreateView.as_view(), name='add-author'), path('authors/add/', AuthorCreateView.as_view(), name='add-author'),
path('books/add/', BooksCreateView.as_view(), name='add-author'), path('books/add/', BooksCreateView.as_view(), name='add-author'),
path('books/<int:pk>/edit/', BooksUpdateView.as_view(), name='edit-book'),
path('authors/<int:pk>/edit/', AuthorUpdateView.as_view(), name='edit-author'),
] ]
...@@ -3,7 +3,7 @@ from django.shortcuts import render ...@@ -3,7 +3,7 @@ from django.shortcuts import render
from django.template import loader from django.template import loader
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 django.views.generic.edit import CreateView, UpdateView
from .models import Author, Books from .models import Author, Books
...@@ -41,6 +41,17 @@ class BooksCreateView(CreateView): ...@@ -41,6 +41,17 @@ class BooksCreateView(CreateView):
fields = '__all__' fields = '__all__'
template_name = 'add-book.html' template_name = 'add-book.html'
class BooksUpdateView(UpdateView):
model = Books
fields = '__all__'
template_name = "edit-book.html"
class AuthorUpdateView(UpdateView):
model = Author
fields = '__all__'
template_name = "edit-author.html"
''' '''
books = Books.objects.filter(author=Author) books = Books.objects.filter(author=Author)
extra_context = {'books': books.author.all()} extra_context = {'books': books.author.all()}
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
{% block content %} {% block content %}
{% block body %} {% block body %}
{% endblock %} {% endblock %}
<button type = "button"
onclick="window.location.href='../edit/'">Edit Author</button>
<a href="/home/">Home</a> <a href="/home/">Home</a>
<a href="/books/">Books</a> <a href="/books/">Books</a>
<a href="/authors/">Authors</a> <a href="/authors/">Authors</a>
......
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
{% block body %} {% block body %}
{% endblock %} {% endblock %}
<button type = "button"
onclick="window.location.href='../edit/'">Edit Book</button>
<a href="/home/">Home</a> <a href="/home/">Home</a>
<a href="/books/">Books</a> <a href="/books/">Books</a>
<a href="/authors/">Authors</a> <a href="/authors/">Authors</a>
......
<form method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Update">
</form>
\ No newline at end of file
<form method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Update">
</form>
\ 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