Fixed all errors and updated readme. Finished coding!

parent 2390f98f
Izaac Daniel B. Muncal | 214138 | CSCI 40-E Izaac Daniel B. Muncal | 214138 | CSCI 40-E
Lab 3 - My Favorite Books and Authors Lab 4 - My Favorite Books and Authors v2
March 28, 2023 April 27, 2023
I independently worked on my project. I only consulted to the given materials in the modules for help. I independently worked on my project. I only consulted to the given materials in the modules for help.
<sgd> Izaac Daniel B. Muncal March 28, 2023 <sgd> Izaac Daniel B. Muncal April 27, 2023
\ No newline at end of file \ No newline at end of file
...@@ -11,4 +11,4 @@ class AuthorForm(forms.ModelForm): ...@@ -11,4 +11,4 @@ class AuthorForm(forms.ModelForm):
class BookForm(forms.ModelForm): class BookForm(forms.ModelForm):
class Meta: class Meta:
model = Books model = Books
fields = '__all__' fields = '__all__'
\ No newline at end of file
from django.db import models from django.db import models
from django.urls import reverse
class Author(models.Model): class Author(models.Model):
first_name = models.CharField(max_length=255) first_name = models.CharField(max_length=255)
...@@ -11,6 +11,11 @@ class Author(models.Model): ...@@ -11,6 +11,11 @@ class Author(models.Model):
def __str__(self): def __str__(self):
return "{} {}".format(self.first_name, self.last_name) return "{} {}".format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse('bookshelf:author-details', kwargs = {'pk':self.pk})
def get_update_url(self):
return reverse('bookshelf:author-edit', kwargs = {'pk':self.pk})
class Books(models.Model): class Books(models.Model):
title = models.CharField(max_length=255) title = models.CharField(max_length=255)
...@@ -22,3 +27,10 @@ class Books(models.Model): ...@@ -22,3 +27,10 @@ class Books(models.Model):
def __str__(self): def __str__(self):
return "{}".format(self.title) return "{}".format(self.title)
def get_absolute_url(self):
return reverse('bookshelf:book-details', kwargs={'pk': self.pk})
def get_update_url(self):
return reverse('bookshelf:book-edit', kwargs={'pk': self.pk})
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
{% load static %} {% load static %}
{% block title %} Add New Author {% endblock %} {% block title %} Add New Author {% endblock %}
{% block content %} {% block header %}{% endblock %}
{% block body %}
{{ form.non_field_errors }} {{ form.non_field_errors }}
{% for field in form %} {% for field in form %}
{% if field.errors %} {% if field.errors %}
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
{% load static %} {% load static %}
{% block title %} Add New Book {% endblock %} {% block title %} Add New Book {% endblock %}
{% block content %} {% block header %}{% endblock %}
{% block body %}
{{ form.non_field_errors }} {{ form.non_field_errors }}
{% for field in form %} {% for field in form %}
{% if field.errors %} {% if field.errors %}
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,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>
<a href="/bookshelf/author/{{author.pk}}/edit"><button>Edit Author</button></a><br><br>
<p><b>Books by {{object.first_name}} {{object.last_name}} I love:</b></p> <p><b>Books by {{object.first_name}} {{object.last_name}} I love:</b></p>
<ul> <ul>
{% for book in object.books_set.all %} {% for book in object.books_set.all %}
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,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>
<a href="/bookshelf/books/{{books.pk}}/edit"><button>Edit Book</button></a><br><br>
<a href="/bookshelf/">Home</a> <a href="/bookshelf/">Home</a>
<a href="/bookshelf/books/">Books</a> <a href="/bookshelf/books/">Books</a>
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
{% load static %} {% load static %}
{% block title %} Edit Author {% endblock %} {% block title %} Edit Author {% endblock %}
{% block content %} {% block header %}{% endblock %}
{% block body %}
{{ form.non_field_errors }} {{ form.non_field_errors }}
{% for field in form %} {% for field in form %}
{% if field.errors %} {% if field.errors %}
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
{% load static %} {% load static %}
{% block title %} Edit Book {% endblock %} {% block title %} Edit Book {% endblock %}
{% block content %} {% block header %}{% endblock %}
{% block body %}
{{ form.non_field_errors }} {{ form.non_field_errors }}
{% for field in form %} {% for field in form %}
{% if field.errors %} {% if field.errors %}
......
...@@ -5,11 +5,11 @@ ...@@ -5,11 +5,11 @@
{% block body %} {% block body %}
<p> I don't read books so these are the only books I have read so far.</p> <p> I don't read books so these are the only books I have read so far.</p>
<a href="/bookshelf/books/">Books</a>----------------------------------------- <a href="/bookshelf/books/">Books</a>-----------------------------------------
<a href="/bookshelf/author/">Authors</a> <a href="/bookshelf/authors/">Authors</a>
<p>
<a href="/bookshelf/books/add">Add Book</a> <a href="/bookshelf/books/add">Add Book</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href = "/bookshelf/authors/add">Add Author</a> <a href = "/bookshelf/authors/add">Add Author</a>
</p>
{% endblock %} {% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import home_view, BooksView, BooksDetailView, AuthorView, AuthorDetailView, BookCreateView, BookUpdateView, AuthorCreateView, AuthorUpdateView from .views import home_view, BooksView, BooksDetailView, AuthorView, AuthorDetailView, BookCreateView, BookUpdateView, \
AuthorCreateView, AuthorUpdateView
urlpatterns = [ urlpatterns = [
path('', home_view, name='home'), path('', home_view, name='home'),
path('books/', BooksView.as_view(), name='books'), path('books/', BooksView.as_view(), name='books'),
path('books/<int:pk>/details/', BooksDetailView.as_view(), name='book-details'), path('books/<int:pk>/details/', BooksDetailView.as_view(), name='book-details'),
path('author/', AuthorView.as_view(), name='author'), path('authors/', AuthorView.as_view(), name='author'),
path('author/<int:pk>/details/', AuthorDetailView.as_view(), name='author-details'), path('author/<int:pk>/details/', AuthorDetailView.as_view(), name='author-details'),
path('books/add/', BookCreateView.as_view(), name='add-book'), path('books/add/', BookCreateView.as_view(), name='add-book'),
path('authors/add/', AuthorCreateView.as_view(), name='add-author'), path('authors/add/', AuthorCreateView.as_view(), name='add-author'),
path('books/<pk>/edit/', BookUpdateView.as_view(), name='edit-book'), path('books/<pk>/edit/', BookUpdateView.as_view(), name='edit-book'),
path('authors/<pk>/edit/', AuthorUpdateView.as_view(), name='edit-author'), path('author/<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
app_name = "bookshelf" app_name = "bookshelf"
\ No newline at end of file
...@@ -2,6 +2,7 @@ from django.shortcuts import render ...@@ -2,6 +2,7 @@ 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 django.views.generic.edit import CreateView, UpdateView
from django.urls import reverse
from .models import Books, Author from .models import Books, Author
...@@ -12,12 +13,12 @@ def home_view(request): ...@@ -12,12 +13,12 @@ def home_view(request):
class AuthorView(ListView): class AuthorView(ListView):
model = Author model = Author
template_name = 'bookshelf/authors.html' template_name = 'bookshelf/author.html'
class AuthorDetailView(DetailView): class AuthorDetailView(DetailView):
model = Author model = Author
template_name = 'bookshelf/author_details.html' template_name = 'bookshelf/author_detail.html'
class BooksView(ListView): class BooksView(ListView):
...@@ -27,7 +28,7 @@ class BooksView(ListView): ...@@ -27,7 +28,7 @@ class BooksView(ListView):
class BooksDetailView(DetailView): class BooksDetailView(DetailView):
model = Books model = Books
template_name = 'bookshelf/books_details.html' template_name = 'bookshelf/books_detail.html'
class AuthorCreateView(CreateView): class AuthorCreateView(CreateView):
......
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