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

Added new Features: Edit Book and Edit Authors

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