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
Lab 03: My Favorite Books and Authors
Date of Submission: 3/27/2023
Lab 04: My Favorite Books and Authors v2
Date of Submission: 4/24/2023
This lab was started, worked on, and finished by me.
<sgd> Alec Isaiah R. Dayupay, 3/27/2023
\ No newline at end of file
<sgd> Alec Isaiah R. Dayupay, 4/24/2023
\ 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 @@
<p>{{ object.age }}</p>
<p>{{ object.nationality }}</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>
{% for books in object.books_set.all %}
<li>
......
......@@ -11,6 +11,7 @@
<p>{{ object.year_published }}</p>
<p>{{ object.ISBN }}</p>
<p>{{ object.blurb }}</p>
<input type="button" value="Edit Book" onclick="location.href='http://localhost:8000/books/{{ object.pk }}/edit/'" />
{% 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 @@
</p>
{% endblock %}
{% block links %}<a href="http://localhost:8000/books/">Books</a> <a href="http://localhost:8000/authors/">Authors</a>{% endblock %}
\ No newline at end of file
{% block links %}<a href="http://localhost:8000/books/">Books</a> <a href="http://localhost:8000/authors/">Authors</a>
<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 . import views
from .views import BooksListView, BooksDetailView, AuthorListView, AuthorDetailView
from .views import (BooksListView, BooksCreateView, BooksDetailView, BooksUpdateView, AuthorListView, AuthorCreateView, AuthorDetailView, AuthorUpdateView)
urlpatterns = [
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('authors/', AuthorListView.as_view(), name="author_list"),
path('authors/<int:pk>/details/', AuthorDetailView.as_view(), name="author_detail")
path('books/', BooksListView.as_view(), name="books"),
path('books/add/', BooksCreateView.as_view(), name="add-book"),
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.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Author, Books
def home(request):
return render(request, "bookshelf/home.html")
class BooksListView(ListView):
model = Books
template_name = 'bookshelf/books.html'
class BooksCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/add-book.html'
class BooksDetailView(DetailView):
model = Books
template_name = 'bookshelf/book_details.html'
class BooksUpdateView(UpdateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/edit-book.html'
class AuthorListView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
class AuthorCreateView(CreateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/add-author.html'
class AuthorDetailView(DetailView):
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