Commit 3674cdce authored by KaoruSawade's avatar KaoruSawade

Implemented editing books: created edit-book.html, edited urls.py and...

Implemented editing books: created edit-book.html, edited urls.py and views.py, & edited books_detail's button's link
parent fea21e8e
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<p>{{ book.ISBN }}</p> <p>{{ book.ISBN }}</p>
<p>{{ book.blurb }}</p> <p>{{ book.blurb }}</p>
<br> <br>
<form action='[insert link to edit-book]' > <form action='edit' >
<input type="submit" value="Edit Book" /> <input type="submit" value="Edit Book" />
</form> </form>
<br> <br>
......
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Book{% endblock %}
{% block content %}
<form action='' method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Edit Book">
</form>
{% endblock %}
from django.urls import path from django.urls import path
from .views import home, AuthorListView, AuthorDetailView, AuthorCreateView, BooksListView, BooksDetailView, BooksCreateView from .views import home, AuthorListView, AuthorDetailView, AuthorCreateView, BooksListView, BooksDetailView, BooksCreateView, BooksEditView
urlpatterns = [ urlpatterns = [
path('home/', home, name='home'), path('home/', home, name='home'),
...@@ -9,6 +9,7 @@ urlpatterns = [ ...@@ -9,6 +9,7 @@ urlpatterns = [
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='books-detail'), path('books/<int:pk>/details', BooksDetailView.as_view(), name='books-detail'),
path('books/add', BooksCreateView.as_view(), name='add-book'), path('books/add', BooksCreateView.as_view(), name='add-book'),
path('books/<int:pk>/edit', BooksEditView.as_view(), name='edit-book'),
] ]
app_name = "bookshelf" app_name = "bookshelf"
...@@ -38,4 +38,9 @@ class BooksDetailView(DetailView): ...@@ -38,4 +38,9 @@ class BooksDetailView(DetailView):
class BooksCreateView(CreateView): class BooksCreateView(CreateView):
model = Books model = Books
fields = '__all__' fields = '__all__'
template_name = 'bookshelf/add-book.html' template_name = 'bookshelf/add-book.html'
\ No newline at end of file
class BooksEditView(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