Commit a1eb2c7b authored by Alec Dayupay's avatar Alec Dayupay

Merged master with lab04

parents e6d7162e a0d170ab
Alec Isaiah R. Dayupay, 211831, CSCI 40-C Alec Isaiah R. Dayupay, 211831, CSCI 40-C
Lab 03: My Favorite Books and Authors Lab 04: My Favorite Books and Authors v2
Date of Submission: 3/27/2023 Date of Submission: 4/24/2023
This lab was started, worked on, and finished by me. This lab was started, worked on, and finished by me.
<sgd> Alec Isaiah R. Dayupay, 3/27/2023 <sgd> Alec Isaiah R. Dayupay, 4/24/2023
\ No newline at end of file \ No newline at end of file
from django.forms import ModelForm
from .models import Books, Author
class BooksForm(ModelForm):
class Meta:
model = Books
fields = '__all__'
class AuthorForm(ModelForm):
class Meta:
model = Author
fields = '__all__'
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% 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' %}
{% load static %}
{% 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
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<p>{{ object.age }}</p> <p>{{ object.age }}</p>
<p>{{ object.nationality }}</p> <p>{{ object.nationality }}</p>
<p>{{ object.bio }}</p> <p>{{ object.bio }}</p>
<input type="button" value="Edit Author" onclick="location.href='http://localhost:8000/authors/{{ object.pk }}/edit/'" />
<p>Books by {{ object.first_name }} {{ object.last_name }} I love:</p> <p>Books by {{ object.first_name }} {{ object.last_name }} I love:</p>
{% for books in object.books_set.all %} {% for books in object.books_set.all %}
<li> <li>
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<p>{{ object.year_published }}</p> <p>{{ object.year_published }}</p>
<p>{{ object.ISBN }}</p> <p>{{ object.ISBN }}</p>
<p>{{ object.blurb }}</p> <p>{{ object.blurb }}</p>
<input type="button" value="Edit Book" onclick="location.href='http://localhost:8000/books/{{ object.pk }}/edit/'" />
{% endblock %} {% endblock %}
{% block links %}<a href="http://localhost:8000/home/">Home</a> <a href="http://localhost:8000/books/">Books</a> <a href="http://localhost:8000/authors/">Authors</a>{% endblock %} {% block links %}<a href="http://localhost:8000/home/">Home</a> <a href="http://localhost:8000/books/">Books</a> <a href="http://localhost:8000/authors/">Authors</a>{% 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 }}
<input type="Submit" value="Save Changes">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% 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
...@@ -12,4 +12,6 @@ ...@@ -12,4 +12,6 @@
</p> </p>
{% endblock %} {% endblock %}
{% block links %}<a href="http://localhost:8000/books/">Books</a> <a href="http://localhost:8000/authors/">Authors</a>{% endblock %} {% block links %}<a href="http://localhost:8000/books/">Books</a> <a href="http://localhost:8000/authors/">Authors</a>
\ No newline at end of file <a href="http://localhost:8000/books/add/">Add Book</a> <a href="http://localhost:8000/authors/add/">Add Author</a>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from . import views from . import views
from .views import BooksListView, BooksDetailView, AuthorListView, AuthorDetailView from .views import (BooksListView, BooksCreateView, BooksDetailView, BooksUpdateView, AuthorListView, AuthorCreateView, AuthorDetailView, AuthorUpdateView)
urlpatterns = [ urlpatterns = [
path('home/', views.home, name="home"), path('home/', views.home, name="home"),
path('books/', BooksListView.as_view(), name="books_list"),
path('books/<int:pk>/details/', BooksDetailView.as_view(), name="books_detail"), path('books/', BooksListView.as_view(), name="books"),
path('authors/', AuthorListView.as_view(), name="author_list"), path('books/add/', BooksCreateView.as_view(), name="add-book"),
path('authors/<int:pk>/details/', AuthorDetailView.as_view(), name="author_detail") path('books/<int:pk>/details/', BooksDetailView.as_view(), name="book_details"),
path('books/<int:pk>/edit/', BooksUpdateView.as_view(), name="edit-book"),
path('authors/', AuthorListView.as_view(), name="authors"),
path('authors/add/', AuthorCreateView.as_view(), name="add-author"),
path('authors/<int:pk>/details/', AuthorDetailView.as_view(), name="author_details"),
path('authors/<int:pk>/edit/', AuthorUpdateView.as_view(), name="edit_author"),
] ]
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
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
from .models import Author, Books from .models import Author, Books
def home(request): def home(request):
return render(request, "bookshelf/home.html") return render(request, "bookshelf/home.html")
class BooksListView(ListView): class BooksListView(ListView):
model = Books model = Books
template_name = 'bookshelf/books.html'
class BooksCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/add-book.html'
class BooksDetailView(DetailView): class BooksDetailView(DetailView):
model = Books model = Books
template_name = 'bookshelf/book_details.html'
class BooksUpdateView(UpdateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/edit-book.html'
class AuthorListView(ListView): class AuthorListView(ListView):
model = Author model = Author
template_name = 'bookshelf/authors.html'
class AuthorCreateView(CreateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/add-author.html'
class AuthorDetailView(DetailView): class AuthorDetailView(DetailView):
model = Author model = Author
template_name = 'bookshelf/author_details.html'
class AuthorUpdateView(UpdateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/edit_author.html'
\ 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