Commit fd327cc3 authored by Caryn Lopez-Go's avatar Caryn Lopez-Go

updated bookshelf with new update and add buttons

parent 02bd157e
Lopez-Go, Caryn Bryne C. (213558) Lopez-Go, Caryn Bryne C. (213558)
CSCI 40 C CSCI 40 C
Lab 3: My Favorite Books and Authors Lab 04: My Favorite Books and Authors v2
March 28, 2023 April 25, 2023
This lab was made by me and only me. This lab was made by me and only me.
<sgd> Caryn Bryne C. Lopez-Go, March 27, 2023 <sgd> Caryn Bryne C. Lopez-Go, April 25, 2023
\ No newline at end of file \ No newline at end of file
{% extends 'base.html' %}
{% block title %}Add New Author{% endblock %}
{% block content %}
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="SUBMIT" value="Add Author">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Add New Book{% endblock %}
{% block content %}
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="SUBMIT" value="Add Book">
</form>
{% endblock %}
\ No newline at end of file
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
{% endfor %} {% endfor %}
</ul> </ul>
<section class="bottom"> <section class="bottom">
<a href="{% url 'bookshelf:edit-author' author.id %}">Edit Author</a><br>
<a href="{% url 'bookshelf:home' %}">Home</a> <a href="{% url 'bookshelf:home' %}">Home</a>
<a href="{% url 'bookshelf:books' %}">Books</a> <a href="{% url 'bookshelf:books' %}">Books</a>
<a href="{% url 'bookshelf:authors' %}">Authors</a> <a href="{% url 'bookshelf:authors' %}">Authors</a>
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
{{ books.blurb }}<br> {{ books.blurb }}<br>
</p> </p>
<section class="bottom"> <section class="bottom">
<a href="{% url 'bookshelf:edit-book' books.id %}">Edit Book</a><br>
<a href="{% url 'bookshelf:home' %}">Home</a> <a href="{% url 'bookshelf:home' %}">Home</a>
<a href="{% url 'bookshelf:books' %}">Books</a> <a href="{% url 'bookshelf:books' %}">Books</a>
<a href="{% url 'bookshelf:authors' %}">Authors</a> <a href="{% url 'bookshelf:authors' %}">Authors</a>
......
{% extends 'base.html' %}
{% block title %}Edit Author{% endblock %}
{% block content %}
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="SUBMIT" value="Save Changes">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Edit Book{% endblock %}
{% block content %}
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="SUBMIT" value="Save Changes">
</form>
{% endblock %}
\ No newline at end of file
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
<section class="bottom"> <section class="bottom">
<a href="{% url 'bookshelf:books' %}">Books</a> <a href="{% url 'bookshelf:books' %}">Books</a>
<a href="{% url 'bookshelf:authors' %}">Authors</a> <a href="{% url 'bookshelf:authors' %}">Authors</a>
<a href="{% url 'bookshelf:add-book' %}">Add Book</a>
<a href="{% url 'bookshelf:add-author' %}">Add Author</a>
</section> </section>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -7,7 +7,11 @@ urlpatterns = [ ...@@ -7,7 +7,11 @@ urlpatterns = [
path('authors/', AuthorsListView.as_view(), name = "authors"), path('authors/', AuthorsListView.as_view(), name = "authors"),
path('authors/<int:pk>/details', AuthorDetailsView.as_view(), name = "author-details"), path('authors/<int:pk>/details', AuthorDetailsView.as_view(), name = "author-details"),
path('books/', BooksListView.as_view(), name = "books"), path('books/', BooksListView.as_view(), name = "books"),
path('books/<int:pk>/details', BookDetailsView.as_view(), name = "book-details") path('books/<int:pk>/details', BookDetailsView.as_view(), name = "book-details"),
path('books/add/', BookCreateView.as_view(), name="add-book"),
path('authors/add/', AuthorCreateView.as_view(), name="add-author"),
path('books/<int:pk>/edit/', BookUpdateView.as_view(), name="edit-book"),
path('authors/<int:pk>/edit/', AuthorUpdateView.as_view(), name="edit-author"),
] ]
app_name = 'bookshelf' app_name = 'bookshelf'
\ No newline at end of file
...@@ -4,11 +4,13 @@ from django.http import HttpResponse ...@@ -4,11 +4,13 @@ from django.http import HttpResponse
from .models import Author, Books from .models import Author, Books
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
from django.views.generic.edit import CreateView, UpdateView
# Create your views here. # Create your views here.
def home(request): def home(request):
return render(request, 'bookshelf/home.html') return render(request, 'bookshelf/home.html')
#Books
class BooksListView(ListView): class BooksListView(ListView):
model = Books model = Books
template_name = 'bookshelf/books.html' template_name = 'bookshelf/books.html'
...@@ -17,10 +19,31 @@ class BookDetailsView(DetailView): ...@@ -17,10 +19,31 @@ class BookDetailsView(DetailView):
model = Books model = Books
template_name = 'bookshelf/book_details.html' template_name = 'bookshelf/book_details.html'
class BookCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/add-book.html'
class BookUpdateView(UpdateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/edit-book.html'
#Authors
class AuthorsListView(ListView): class AuthorsListView(ListView):
model = Author model = Author
template_name = 'bookshelf/authors.html' template_name = 'bookshelf/authors.html'
class AuthorDetailsView(DetailView): class AuthorDetailsView(DetailView):
model = Author model = Author
template_name = 'bookshelf/author_details.html' template_name = 'bookshelf/author_details.html'
\ No newline at end of file
class AuthorCreateView(CreateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/add-author.html'
class AuthorUpdateView(UpdateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/edit-author.html'
\ No newline at end of file
No preview for this file type
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