Commit b8960cac authored by Matthew Josh Benedict Benito's avatar Matthew Josh Benedict Benito

Merge branch 'lab04' into 'master'

Lab04

See merge request !1
parents 80e57f21 ff06d1ce
Matthew Josh Benedict R. Benito, 210857, 2 CS-DGDD, CSCI 40-F
Lab 03: My Favorite Books and Authors
Lab 04: My Favorite Books and Authors v2
May 20, 2023
All of this code was created by myself with my own understanding and knowledge. The only assistance I referred to is through the Canvas slides or consultation from the professor
<sgd> Matthew Josh Benedict R. Benito, May, 20 2023
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Add New Author{% endblock %}
{% block content %}
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add Author">
</form>
{% endblock %}
{% block scripts %}
{% endblock %}
{% extends 'base.html' %}
{% block title %}Add New Book{% endblock %}
{% block content %}
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add Book">
</form>
{% endblock %}
{% block scripts %}
{% endblock %}
......@@ -5,16 +5,17 @@
<h1>{{ author }}</h1>
<h3>{{ author.age }}<br>
{{ author.nationality }}<br>
{{ author.bio }}</h3><br>
{{ author.bio }}</h3>
<a href="/authors/{{ author.pk }}/edit"><input type="submit" value="Edit Author"></a><br>
<h3> Books by {{ author }} I love:</h3>
<ul>
{% for book in author.books_set.all %}
<li><a href="http://127.0.0.1:8000/{{ book.get_absolute_url }}">{{ book.title }}</a></li>
<li><a href="{{ book.get_absolute_url }}">{{ book.title }}</a></li>
{% endfor %}
</ul>
{% endblock %}
{% block scripts %}
<a href="http://127.0.0.1:8000/home">Home</a>
<a href="http://127.0.0.1:8000/books">Books</a>
<a href="http://127.0.0.1:8000/authors">Authors</a>
<a href="/home">Home</a>
<a href="/books">Books</a>
<a href="/authors">Authors</a>
{% endblock %}
......@@ -10,7 +10,8 @@
{{ book.blurb }}</h3>
{% endblock %}
{% block scripts %}
<a href="http://127.0.0.1:8000/home">Home</a>
<a href="http://127.0.0.1:8000/books">Books</a>
<a href="http://127.0.0.1:8000/authors">Authors</a>
<a href="/books/{{ book.pk }}/edit"><input type="submit" value="Edit Book"></a><br>
<a href="/home">Home</a>
<a href="/books">Books</a>
<a href="/authors">Authors</a>
{% endblock %}
{% extends 'base.html' %}
{% block title %}Edit Author{% endblock %}
{% block content %}
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes">
</form>
{% endblock %}
{% block scripts %}
{% endblock %}
{% extends 'base.html' %}
{% block title %}Edit Book{% endblock %}
{% block content %}
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes">
</form>
{% endblock %}
{% block scripts %}
{% endblock %}
......@@ -14,6 +14,8 @@
I also try to watch their animated versions when they release </h3><br><br>
{% endblock %}
{% block scripts %}
<a href="http://127.0.0.1:8000/books">Books</a>
<a href="http://127.0.0.1:8000/authors">Authors</a>
<a href="/books">Books</a>
<a href="/authors">Authors</a><br>
<a href="/books/add">Add Book</a>
<a href="/authors/add">Add Author</a>
{% endblock %}
from django.urls import path
from .views import homepage_view, BooksListView, BooksDetailView, AuthorListView, AuthorDetailView
from .views import homepage_view, BooksListView, BooksDetailView, BooksCreateView, BooksUpdateView, AuthorListView, AuthorDetailView, AuthorCreateView, AuthorUpdateView
urlpatterns = [
path('home/', homepage_view, name='home'),
path('books/', BooksListView.as_view(), name='books-list'),
path('books/<int:pk>/details', BooksDetailView.as_view(), name='book-details'),
path('books/add/', BooksCreateView.as_view(), name='add-book'),
path('books/<int:pk>/edit', BooksUpdateView.as_view(), name='edit-book'),
path('authors/', AuthorListView.as_view(), name='authors-list'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='author-details'),
path('authors/add/', AuthorCreateView.as_view(), name='add-author'),
path('authors/<int:pk>/edit', AuthorUpdateView.as_view(), name='edit-author'),
]
app_name = "bookshelf"
from django.shortcuts import render
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
# Create your views here.
from .models import Books, Author
......@@ -20,7 +21,16 @@ class BooksDetailView(DetailView):
model = Books
def get(self, request, pk):
return render(request, 'bookshelf/book_details.html', {'book': self.model.objects.get(pk=pk)})
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):
model = Author
......@@ -32,6 +42,14 @@ class AuthorDetailView(DetailView):
model = Author
def get(self, request, pk):
return render(request, 'bookshelf/author_details.html', {'author': self.model.objects.get(pk=pk)})
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'
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