Commit 597c1efa authored by Sharmaine Chua's avatar Sharmaine Chua

added the feature to update the author and book

parent 139b0a03
...@@ -23,6 +23,11 @@ ...@@ -23,6 +23,11 @@
{% endfor %} {% endfor %}
</h3> </h3>
<a href="./edit">
<button type="button"><p>Edit Authors</p></button>
</a>
<br><br>
{# the links to other html files #} {# the links to other html files #}
<center> <center>
<div class="btn"> <div class="btn">
......
...@@ -18,6 +18,11 @@ ...@@ -18,6 +18,11 @@
Blurb: {{ object.blurb }} <br> Blurb: {{ object.blurb }} <br>
</h3> </h3>
<a href="./edit">
<button type="button"><p>Edit Book</p></button>
</a>
<br><br>
{# the links to other html files #} {# the links to other html files #}
<center> <center>
<div class="btn"> <div class="btn">
......
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Author{% endblock %}
{% block content %}
<div class="edit-author">
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save">
</form>
</div>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Book{% endblock %}
{% block content %}
<div class="edit_book">
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save">
</form>
</div>
{% endblock %}
\ No newline at end of file
...@@ -5,10 +5,12 @@ urlpatterns = [ ...@@ -5,10 +5,12 @@ urlpatterns = [
path('home/',index,name='home'), path('home/',index,name='home'),
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='create_book'),
path('books/<int:pk>/edit',BooksUpdateView.as_view(),name='update_book'),
path('authors/',AuthorListView.as_view(),name='author_list'), path('authors/',AuthorListView.as_view(),name='author_list'),
path('authors/<int:pk>/details',AuthorDetailView.as_view(),name='author_details'), path('authors/<int:pk>/details',AuthorDetailView.as_view(),name='author_details'),
path('books/add',BooksCreateView.as_view(),name='create_book'),
path('authors/add',AuthorCreateView.as_view(),name='new_author'), path('authors/add',AuthorCreateView.as_view(),name='new_author'),
path('authors/<int:pk>/edit',AuthorUpdateView.as_view(),name='update_author'),
] ]
app_name = 'bookshelf' app_name = 'bookshelf'
\ No newline at end of file
...@@ -2,7 +2,7 @@ from django.shortcuts import render ...@@ -2,7 +2,7 @@ from django.shortcuts import render
from django.http import HttpResponse, request from django.http import HttpResponse, request
from django.views import View from django.views import View
from .models import Author, Books from .models import Author, Books
from django.views.generic.edit import CreateView from django.views.generic.edit import CreateView, UpdateView
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
...@@ -23,6 +23,11 @@ class BooksCreateView(CreateView): ...@@ -23,6 +23,11 @@ class BooksCreateView(CreateView):
template_name = 'bookshelf/add-book.html' template_name = 'bookshelf/add-book.html'
fields = '__all__' fields = '__all__'
class BooksUpdateView(UpdateView):
model = Books
template_name = 'bookshelf/edit-book.html'
fields = '__all__'
class AuthorListView(ListView): class AuthorListView(ListView):
model = Author model = Author
template_name='bookshelf/authors.html' template_name='bookshelf/authors.html'
...@@ -35,3 +40,8 @@ class AuthorCreateView(CreateView): ...@@ -35,3 +40,8 @@ class AuthorCreateView(CreateView):
model = Author model = Author
template_name = 'bookshelf/add-author.html' template_name = 'bookshelf/add-author.html'
fields = '__all__' fields = '__all__'
class AuthorUpdateView(UpdateView):
model = Author
template_name = 'bookshelf/edit-author.html'
fields = '__all__'
\ No newline at end of file
This diff is collapsed.
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