Commit fcc03be8 authored by Nate Brevin A. Que's avatar Nate Brevin A. Que

Updated the 'Per Book's Details' page to include a button to edit the book and...

Updated the 'Per Book's Details' page to include a button to edit the book and Implemented the 'Edit Book' page using UpdateView and configuring urls.py
parent 2f4a2e67
...@@ -10,7 +10,8 @@ ...@@ -10,7 +10,8 @@
{{ book.blurb }} </h3> {{ book.blurb }} </h3>
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<a href="http://127.0.0.1:8000/home">Home</a> <a href="/books/{{ book.pk }}/edit"><input type="submit" value="Edit Book"></a><br>
<a href="http://127.0.0.1:8000/books">Books</a> <a href="/home">Home</a>
<a href="http://127.0.0.1:8000/authors">Authors</a> <a href="/books">Books</a>
<a href="/authors">Authors</a>
{% endblock %} {% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% 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 scripts %}
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import (homepage_view, BooksListView, BooksDetailView, BooksCreateView, from .views import (homepage_view, BooksListView, BooksDetailView, BooksCreateView, BooksUpdateView,
AuthorListView, AuthorDetailView, AuthorCreateView) AuthorListView, AuthorDetailView, AuthorCreateView)
urlpatterns = [ urlpatterns = [
...@@ -8,6 +8,7 @@ urlpatterns = [ ...@@ -8,6 +8,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='book-details'), path('books/<int:pk>/details', BooksDetailView.as_view(), name='book-details'),
path('books/add/', BooksCreateView.as_view(), name='add-book'), 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='authors-list'), path('authors/', AuthorListView.as_view(), name='authors-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/add/', AuthorCreateView.as_view(), name='add-author'),
......
from django.shortcuts import render 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, UpdateView
from .models import Books, Author from .models import Books, Author
...@@ -30,6 +30,12 @@ class BooksCreateView(CreateView): ...@@ -30,6 +30,12 @@ class BooksCreateView(CreateView):
template_name = 'bookshelf/add-book.html' template_name = 'bookshelf/add-book.html'
class BooksUpdateView(UpdateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/edit-book.html'
class AuthorListView(ListView): class AuthorListView(ListView):
model = Author model = Author
......
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