Commit f4f6394a authored by Stefan Gomez's avatar Stefan Gomez

Updated the "Per Book's Details' page to add an "Edit Book" button and created...

Updated the "Per Book's Details' page to add an "Edit Book" button and created the appropriate page whenever that button is clicked.
parent 173cca92
...@@ -12,4 +12,7 @@ ...@@ -12,4 +12,7 @@
<p>{{ book.blurb }}</p> <p>{{ book.blurb }}</p>
{% endblock %} {% endblock %}
{% block footer %}<a href="/home">Home</a> | <a href="/books">Books</a> | <a href="/authors">Authors</a>{% endblock %} {% block footer %}
\ No newline at end of file <a href="/books/{{ book.pk }}/edit"><input type="submit" value="Edit Book"></a>
<br><a href="/home">Home</a> | <a href="/books">Books</a> | <a href="/authors">Authors</a>
{% endblock %}
\ No newline at end of file
{% 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="Save Changes">
</form>
{% endblock %}
{% block footer %}{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import home, BooksView, PerBooksView, AddBooksView, AuthorsView, PerAuthorsView, AddAuthorsView from .views import home, BooksView, PerBooksView, AddBooksView, EditBooksView, AuthorsView, PerAuthorsView, AddAuthorsView
urlpatterns = [ urlpatterns = [
...@@ -8,6 +8,7 @@ urlpatterns = [ ...@@ -8,6 +8,7 @@ urlpatterns = [
path('books', BooksView.as_view(), name='books'), path('books', BooksView.as_view(), name='books'),
path('books/<int:pk>/details', PerBooksView.as_view(), name='book-detail'), path('books/<int:pk>/details', PerBooksView.as_view(), name='book-detail'),
path('books/add/', AddBooksView.as_view(), name='add-book'), path('books/add/', AddBooksView.as_view(), name='add-book'),
path('books/<int:pk>/edit', EditBooksView.as_view(), name='edit-book'),
path('authors', AuthorsView.as_view(), name='authors'), path('authors', AuthorsView.as_view(), name='authors'),
path('authors/<int:pk>/details', PerAuthorsView.as_view(), name='author-detail'), path('authors/<int:pk>/details', PerAuthorsView.as_view(), name='author-detail'),
path('authors/add/', AddAuthorsView.as_view(), name='add-author'), path('authors/add/', AddAuthorsView.as_view(), name='add-author'),
......
...@@ -2,6 +2,7 @@ from django.shortcuts import render ...@@ -2,6 +2,7 @@ from django.shortcuts import render
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
from django.views.generic.edit import UpdateView
from .models import Author, Book from .models import Author, Book
...@@ -26,6 +27,12 @@ class AddBooksView(CreateView): ...@@ -26,6 +27,12 @@ class AddBooksView(CreateView):
template_name = 'bookshelf/add-book.html' template_name = 'bookshelf/add-book.html'
class EditBooksView(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'
......
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