Commit 047f310b authored by Angelo Alvarez's avatar Angelo Alvarez

Added new Features: Edit Book and Edit Authors

parent 9287decf
......@@ -6,10 +6,7 @@
<form method="POST">
{% csrf_token %}
{% for field in form %}
{{field.label}}: {{ field }}
<span class="spacer"></span>
{% endfor %}
{{ form.as_p }}
<button type="Submit">Add Author</button>
</form>
......
......@@ -6,10 +6,7 @@
<form method="POST">
{% csrf_token %}
{% for field in form %}
{{field.label}}: {{ field }}
<span class="spacer"></span>
{% endfor %}
{{ form.as_p }}
<button type="Submit">Add Book</button>
</form>
......
......@@ -7,18 +7,28 @@
<b>Age: </b> {{ object.age }}<br>
<b>Nationality: </b>{{ object.nationality }} <br>
{{ object.bio }}
<span class="spacer"></span>
<div id="links">
<form action="../edit">
<button type="Submit">Edit Author</button>
</form>
</div>
<hr>
Books by {{ object.first_name }} {{ object.last_name }} I love:
<ul>
{% for book in books %}
{% if book.author.first_name == object.first_name and book.author.last_name == object.last_name %}
<li><a href="{{ book.get_absolute_url }}">{{ book.title }}</a></li>
{% endif %}
{% for book in object.books_set.all %}
<li>
<a href="{{ book.get_absolute_url }}"> {{ book.title }} </a>
</li>
{% endfor %}
</ul>
<div id="links" style="margin: auto; text-align: center; width: 100%">
<hr>
<div id="links">
<a href="/bookshelf/home/">Home</a>
&nbsp; &nbsp;
<a href="/bookshelf/books/">Books</a>
......
......@@ -9,9 +9,16 @@
<b>Year published: </b>{{ object.year_published }} <br>
<b>ISBN: </b>{{ object.ISBN }} <br>
{{ object.blurb }}
<div id="links">
<form action="../edit">
<button type="Submit">Edit Book</button>
</form>
</div>
<hr>
<div id="links" style="margin: auto; text-align: center; width: 100%">
<div id="links">
<a href="/bookshelf/home/">Home</a>
&nbsp; &nbsp;
<a href="/bookshelf/books/">Books</a>
......
{% extends 'base.html' %}
{% load static %}
{% block title %} Edit Author {% endblock %}
{% block content %}
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<button type="Submit">Save Changes</button>
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} Edit Book {% endblock %}
{% block content %}
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<button type="Submit">Save Changes</button>
</form>
{% endblock %}
\ No newline at end of file
......@@ -26,12 +26,12 @@ works of classic literature as I progress through my college career.
<hr>
<div id="links" style="margin: auto; text-align: center; width: 100%">
<div id="links">
<a href="../books/">Books</a>
&nbsp; &nbsp;
<a href="../authors/">Authors</a>
</div>
<div id="links" style="margin: auto; text-align: center; width: 100%">
<div id="links">
<a href="../books/add">Add Book</a>
&nbsp; &nbsp;
<a href="../authors/add">Add Author</a>
......
from django.urls import path
from .views import home, BooksListView, BooksDetailView, AuthorListView, AuthorDetailView, BooksCreateView, AuthorCreateView
from .views import home, BooksListView, BooksDetailView, AuthorListView, AuthorDetailView, BooksCreateView, AuthorCreateView, BooksUpdateView, AuthorUpdateView
urlpatterns = [
......@@ -9,11 +9,13 @@ urlpatterns = [
path('books/', BooksListView.as_view(), name='books-list'),
path('books/<int:pk>/details/', BooksDetailView.as_view(), name='books-details'),
path('books/add/', BooksCreateView.as_view(), name='add-book'),
path('books/<int:pk>/edit/', BooksUpdateView.as_view(), name='edit-book'),
#Authors
path('authors/', AuthorListView.as_view(), name='authors-list'),
path('authors/<int:pk>/details/', AuthorDetailView.as_view(), name='authors-details'),
path('authors/add/', AuthorCreateView.as_view(), name='add-author'),
path('authors/<int:pk>/edit/', AuthorUpdateView.as_view(), name='edit-author')
]
# This might be needed, depending on your Django version
......
......@@ -2,7 +2,7 @@ from django.shortcuts import render
from django.views import View
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.views.generic.edit import CreateView
from django.views.generic.edit import CreateView, UpdateView
from .models import Books, Author
# Create your views here.
......@@ -21,7 +21,12 @@ class BooksDetailView(DetailView):
model = Books
class BooksCreateView(CreateView):
template_name = 'bookshelf/add_book.html'
template_name = 'bookshelf/add-book.html'
model = Books
fields = '__all__'
class BooksUpdateView(UpdateView):
template_name = 'bookshelf/edit-book.html'
model = Books
fields = '__all__'
......@@ -34,10 +39,13 @@ class AuthorListView(ListView):
class AuthorDetailView(DetailView):
template_name = 'bookshelf/author_detail.html'
model = Author
booklist = Books.objects.all()
extra_context = { 'books' : booklist }
class AuthorCreateView(CreateView):
template_name = 'bookshelf/add_author.html'
template_name = 'bookshelf/add-author.html'
model = Author
fields = '__all__'
class AuthorUpdateView(UpdateView):
template_name = 'bookshelf/edit-author.html'
model = Author
fields = '__all__'
\ No newline at end of file
......@@ -41,4 +41,14 @@ ul li {
.spacer {
display: block;
margin-bottom: 0.5em;
}
#links {
margin: auto;
text-align: center;
width: auto;
}
button {
margin: 10px;
}
\ 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