Commit 6b9af395 authored by Gabriel Geraldo's avatar Gabriel Geraldo

implemented add and edit book features

parent 60700b3e
{% extends 'base.html' %}
{% load static %}
{% block title %} Add New Book {% endblock %}
{% block style %}
<link rel='stylesheet' type='text/css' href="{% static 'base.css' %}"/>
{% endblock %}
{% block content %}
<header>Add New Book</header>
<section>
<form method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add Book">
</form>
</section>
{% endblock %}
\ No newline at end of file
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
<li class="subinfo">Year Published: {{ object.year_published}}</li> <li class="subinfo">Year Published: {{ object.year_published}}</li>
<li class="subinfo">ISBN: {{ object.isbn }}</li> <li class="subinfo">ISBN: {{ object.isbn }}</li>
<li class="subinfo">Short Description: <br>{{ object.blurb }}</li> <li class="subinfo">Short Description: <br>{{ object.blurb }}</li>
<form action="edit">
<input type="submit" value="Edit Book" />
</form>
</ul> </ul>
</section> </section>
<nav> <nav>
...@@ -31,5 +34,4 @@ ...@@ -31,5 +34,4 @@
<a class="primary-link" href="../../authors">Authors</a> <a class="primary-link" href="../../authors">Authors</a>
</div> </div>
</nav> </nav>
{% endblock %} {% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %} Edit Book {% endblock %}
{% block style %}
<link rel='stylesheet' type='text/css' href="{% static 'base.css' %}"/>
{% endblock %}
{% block content %}
<header>Edit Book</header>
<section>
<form method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes">
</form>
</section>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import index_view, home_view, BooksListView, BooksDetailView, AuthorListView, AuthorDetailView from .views import index_view, home_view, BooksListView, BooksDetailView, BooksCreateView, BooksUpdateView, AuthorListView, AuthorDetailView
urlpatterns = [ urlpatterns = [
...@@ -7,6 +7,8 @@ urlpatterns = [ ...@@ -7,6 +7,8 @@ urlpatterns = [
path('home/', home_view, name='home'), path('home/', home_view, name='home'),
path('books/', BooksListView.as_view(template_name='bookshelf/books.html'), name='books'), path('books/', BooksListView.as_view(template_name='bookshelf/books.html'), name='books'),
path('books/<int:pk>/details', BooksDetailView.as_view(template_name='bookshelf/book_details.html'), name='book_details'), path('books/<int:pk>/details', BooksDetailView.as_view(template_name='bookshelf/book_details.html'), name='book_details'),
path('books/add', BooksCreateView.as_view(), name='books_add'),
path('books/<int:pk>/edit', BooksUpdateView.as_view(), name="books_edit"),
path('authors/', AuthorListView.as_view(template_name='bookshelf/authors.html'), name='authors'), path('authors/', AuthorListView.as_view(template_name='bookshelf/authors.html'), name='authors'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(template_name='bookshelf/author_details.html'), name='author_details'), path('authors/<int:pk>/details', AuthorDetailView.as_view(template_name='bookshelf/author_details.html'), name='author_details'),
] ]
......
from django.shortcuts import render from django.shortcuts import render
from django.views import View from django.views import View
from django.views.generic.edit import CreateView, UpdateView
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.list import ListView from django.views.generic.list import ListView
...@@ -23,6 +24,17 @@ class BooksListView(ListView): ...@@ -23,6 +24,17 @@ class BooksListView(ListView):
class BooksDetailView(DetailView): class BooksDetailView(DetailView):
model = Books model = Books
class BooksCreateView(CreateView):
model = Books
fields = "__all__"
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
......
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>{% block title %}My amazing site{% endblock %}</title> <title>{% block title %}{% endblock %}</title>
{% block style %}{% endblock %} {% block style %}{% endblock %}
{% block scripts %} {% endblock %} {% block scripts %} {% endblock %}
</head> </head>
......
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