Created the edit feature

Added a button in the details page to update existing info of authors and books
parent 9f398dc1
...@@ -6,6 +6,12 @@ ...@@ -6,6 +6,12 @@
<h3> Nationality: {{ object.nationality }} </h3> <h3> Nationality: {{ object.nationality }} </h3>
<h3> About the Author: </h3> <p> {{ object.bio }} </p> <h3> About the Author: </h3> <p> {{ object.bio }} </p>
<button type="button">
<a href="/authors/{{object.pk}}/edit"> Edit Author </a>
</button>
<br> <br>
Books by {{ object.first_name }} {{ object.last_name }} I love: Books by {{ object.first_name }} {{ object.last_name }} I love:
<ul> <ul>
{% for book in object.books.all%} {% for book in object.books.all%}
......
...@@ -8,6 +8,12 @@ ...@@ -8,6 +8,12 @@
<h3> ISBN: {{ object.ISBN }}</h3> <h3> ISBN: {{ object.ISBN }}</h3>
<h3> Blurb: </h3> <p> {{ object.blurb }} </p> <h3> Blurb: </h3> <p> {{ object.blurb }} </p>
<button type="button">
<a href="/books/{{object.pk}}/edit"> Edit Book </a>
</button>
<br> <br>
<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>
......
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Author{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{% for field in form %}
{{field.label}}:{{field}} <br><br>
{% endfor %}
<input type="submit" value="Save Changes">
</form>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Book{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{% for field in form %}
{{field.label}}:{{field}} <br><br>
{% endfor %}
<input type="submit" value="Save Changes">
</form>
{% endblock %}
...@@ -2,7 +2,8 @@ from django.urls import path ...@@ -2,7 +2,8 @@ from django.urls import path
from .views import ( from .views import (
home, BooksListView, BooksDetailView, AuthorListView, home, BooksListView, BooksDetailView, AuthorListView,
AuthorDetailView, BooksCreateView, AuthorsCreateView AuthorDetailView, BooksCreateView, AuthorsCreateView,
BooksUpdateView, AuthorsUpdateView
) )
...@@ -12,8 +13,10 @@ path('books/', BooksListView.as_view(), name='books-list'), ...@@ -12,8 +13,10 @@ 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('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-detail'), path('authors/<int:pk>/details/', AuthorDetailView.as_view(), name='author-detail'),
path('books/add/', BooksCreateView.as_view(), name = 'add-book'), path('books/add/', BooksCreateView.as_view(), name ='add-book'),
path('authors/add/', AuthorsCreateView.as_view(), name = 'add-author') path('authors/add/', AuthorsCreateView.as_view(), name ='add-author'),
path('books/<int:pk>/edit/', BooksUpdateView.as_view(), name='update-book'),
path('authors/<int:pk>/edit/', AuthorsUpdateView.as_view(), name='update-author'),
] ]
......
...@@ -34,3 +34,12 @@ class AuthorsCreateView(CreateView): ...@@ -34,3 +34,12 @@ class AuthorsCreateView(CreateView):
fields = '__all__' fields = '__all__'
template_name = 'bookshelf/add-author.html' template_name = 'bookshelf/add-author.html'
class BooksUpdateView(UpdateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/edit-book.html'
class AuthorsUpdateView(UpdateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/edit-author.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